response-callbacks
Manually dealing with responses can be tedious and memorizing what every code means isnt something i enjoy doing. So I put together a list of common callbacks that can be used with the response object.
Install
npm install --save response-callbacks
Example Usage
response-callbacks takes in two parameters. Response and an object containing methods you want called back to.
let callBacks = { console } { console } { console } // You can use the status code directly as well. 420: { console } let request = // response-callbacks returns the original response so you can continue using promises like normalrequest
Callback Methods
I put together a list of most used methods. Optionally you can just have the actual status code in your object and it will be called as well.
200's
success: 2** // Every 200 requestok: 200created: 201no_content: 204
300's
redirection: 3** // Every 300 requestmoved_permanently: 301not_modified: 304
400's
client_error: 4** // Every 400 requestbad_request: 400unauthorized: 401forbidden: 403not_found: 404conflict: 409unprocessable_entity: 422validation: 422 // Used for things like form errors
500's
server_error: 5** // Every 500 requestinternal_server_error: 500bad_gateway: 502service_unavailable: 503gateway_timeout: 504