python - RESTful API Returning Proper Errors -


i building restful api first time class project, confusing me error handling scenarios.

when client request:

https://localhost:8080/api/v1/user/<username> 

i check username variable numerous things such as:

  • if username empty or "blank"
  • if username alphanumerical
  • if length of username short or long

so, code looks @ moment, (it's in python, irrelevant):

# grabbed username variable  # if username blank, return 404 if not username:     abort(404) # if username not alphanumerical, return 404 if not alias.isalnum():     abort(404) # if username length less 4 or greater 25, return 404 if len(alias) < 4 or len(alias) > 25:     abort(404) 

returning 404 errors no means of error "identification" seems wrong me.

should returning 404 error codes displaying went wrong (e.g. "the username given not alphanumerical")?

should returning different http status code other 404?

i incredibly confused!

there many types of http status code, rest api should return correct code scenario.

here resource: http://www.restapitutorial.com/httpstatuscodes.html

also, respond json payload offers developer. simple this:

{     “kind”: “error#404”,     “message”: string, // give short message error     “more-info”: string // provide more detailed error report } 

hope helps.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -