adaltas / node-http-status

Utility to interact with HTTP status code in Node.js
Other
441 stars 55 forks source link

Expose status code series? #33

Closed ckeboss closed 4 years ago

ckeboss commented 4 years ago

Would you be interested in a pull request including the status code series? Spring does this with it's HttpStatus utility: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/HttpStatus.Series.html

Something like

{
  100: 'Continue',
  '100_NAME': 'CONTINUE',
  '100_MESSAGE': 'The server has received the request headers and the client should proceed to send the request body.',
  '100_SERIES': extra.series.INFORMATIONAL
  CONTINUE: 100,
}

Would allow functionality such as:

const responseStatus = status.METHOD_NOT_ALLOWED

if (status[`${responseStatus}_SERIES`] === status.extra.series.CLIENT_ERROR) {

}
wdavidw commented 4 years ago

Hi @ckeboss, if this feature is helpful our userbase then yes, I'll be happy to integrate the pull request. I'll also appreciate if you found the time to enrich the readme. Concerning the implementation, I don't think the series property shall be inside extra. extra children are meant to enrich existing status code by merging them. In cour case, series codes are not HTTP code. I propose to move series at the parent level which would give status.series.CLIENT_ERROR for exemple.