Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-standard response codes #19

Closed
davidfells opened this issue Jul 17, 2015 · 3 comments
Closed

Support non-standard response codes #19

davidfells opened this issue Jul 17, 2015 · 3 comments
Assignees

Comments

@davidfells
Copy link

It's not unsual for APIs, especially private ones, to use non-standard response codes in the 400 range for specific errors. As is, the module does not allow this - it will convert any non-standard code to a 500. As an example here's what I'm doing in my app:

  var err = http_errors(471, 'Invalid API Key.')
  err.status = 471;

Ideally, in my opinion, there would be a way to pass an array of additional codes when requiring the library, which would allow us to easily have a JSON file containing our extended error codes while allowing the library to validate the code against the list of available/valid codes.

@dougwilson dougwilson self-assigned this Jul 17, 2015
@hacksparrow
Copy link
Member

What would be the value of err.name in such a case?

  • Unassigned
  • NonStandardError
  • CustomError
  • Error
  • ?

@jonathanong
Copy link
Member

maybe we should add jshttp/statuses#5 and allow for custom err.name for each status code?

@dougwilson
Copy link
Contributor

For @hacksparrow question, we can just treat it like the x00 class name, from https://tools.ietf.org/html/rfc7231#section-6

HTTP status codes are extensible. HTTP clients are not required to
understand the meaning of all registered status codes, though such
understanding is obviously desirable. However, a client MUST
understand the class of any status code, as indicated by the first
digit, and treat an unrecognized status code as being equivalent to
the x00 status code of that class, with the exception that a
recipient MUST NOT cache a response with an unrecognized status code.

For example, if an unrecognized status code of 471 is received by a
client, the client can assume that there was something wrong with its
request and treat the response as if it had received a 400 (Bad
Request) status code. The response message will usually contain a
representation that explains the status.

@dougwilson dougwilson mentioned this issue Feb 14, 2017
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants