ganomede-errors
Ganomede's extended restify errors
The way to distinguish our app's logic-level errors from others.
(Like socket hang up
vs user already exists
.)
Basic Usage
The idea is to create error classes like UserNotFoundError extends GanomedeError
,
define appropriate statusCode
and message
on it with optional params,
and return those from lower-level places.
//// Database.js//{thisredis;}DbDocumentNotFoundError ={super'No documents matching `%j`' query;thisseverity = 'info';thisstatusCode = 404;};
In app-code, make use of more meaningful errors and act accordingly.
//// app.js//app;
It can also be sometimes useful to have more granular error classes.
//// Orm.js//const findUser = {;};
Included Errors
Some situations are quite common, so error classes for them with appropriate severity levels, status codes and names are already included.
Class Name (as exported) | HTTP Status | Rest Code | Message | Severity |
---|---|---|---|---|
InvalidAuthTokenError |
401 | 'InvalidAuthTokenError' |
Invalid auth token | severity.info |
InvalidCredentialsError |
401 | 'InvalidCredentialsError' |
Invalid credentials | severity.info |
RequestValidationError |
400 | First argument passed to constructor | Rest of constructor arguments | severity.info |
if !reqparamstokenreturn ;if reqheaders'Authorization' !== 'Bearer 0xdeadbeef'return ;if typeof reqbodymessage !== 'string'return;