throw-hydra
HTTP Status Code Handler
An HTTP Error collection to use in your next Hydra REST API.
This is a JSON-LD/Hydra adaptation of https://github.com/kbariotis/throw.js
Installation
npm install throw-hydra.js
Example
var express = ;var app = ;var throwjs = ;var logger = ; app; app; app; var server = app;
Custom Errors
throwjs;
Optional Parameters:
- title[optional]: Title error. Defaults to RFC7231 title if non supplied.
- statusCode[optional]: The HTTP Status number to return, multiple status Codes can be provided in addition to the default one. This allows to augment standard HTTP Status Codes (e.g. 403, with a custom, application-specific status code).
- description[optional]: A detailed description of the error to provide the user with more context.
- type[optional]: A JSON-LD/hydra property allowing you to specify the type of this status code (e.g. type = "Error"). See Hydra's documentaiton for more information.
- next[optional]: The next logical place for the user to navigate to. See hydra:next
- previous[optional]: URL leading to this error. See hydra:previous
An example of the options in action could be:
;
Errors
All of the classes below have all parameters set up by default, based on RFC7231.
But you can override the message
and the errorCode
to fit your for personal needs.
400 Bad Request
throwjs;
401 Unauthorized
throwjs;
402 Payment Required
throwjs;
403 Forbidden
throwjs;
404 Not Found
throwjs;
405 Method Not Allowed
throwjs;
406 Not Acceptable
throwjs;
407 Proxy Authentication Required
throwjs;
408 Request Timeout
throwjs;
409 Conflict
throwjs;
410 Gone
throwjs;
422 Unprocessable Entity
throwjs;
424 Failed Dependency
throwjs;
500 Internal Server Error
throwjs;
501 Not Implemented
throwjs;
502 Bad Gateway
throwjs;
503 Service Unavailable
throwjs;
504 Gateway Timeout
throwjs;
505 HTTP Version Not Supported
throwjs;
511 Network Authentication Required
throwjs;
TODO
- Implement more Error Classes