-
Notifications
You must be signed in to change notification settings - Fork 1
Error – API
Bartosz Łaniewski edited this page Mar 30, 2018
·
1 revision
import errors, {handlers, defineError} from "inra-server-error";
A simple, yet powerful error handler shipped as a middleware for Koa. Defines a global error handler which will generate responses when exceptions are thrown inside your app. Returns two kinds of messages:
- a
userMessage
which is intended to be shown for final clients; - a
developerMessage
which is intended to be used for debuggins and error tracking (disabled onproduction
);
{
"status": 500,
"errorCode": "ERR_CONSTANT_SERVICE_BAR",
"userMessage": "Something went wrong!",
"developerMessage": "Stacktrace, error details",
}
Returns a Koa middleware which can be used inside app.use()
.
Returns a Map
containing all created error definitions.
Adds an error definition to the list. Defines an error handler for a specified exception type.
app.use(errors({
httpStatus: 500, // default HTTP Status,
userMessage: "Internal Error" // default user message
}));
defineError({instance: AuthError});
defineError({instance: ConnectionError, errorCode: "…"});
defineError({instance: ValidationError, httpStatus: 400});
This Wiki and indvidual modules READMEs contains a lot of information – please take your time and read these instructions carefully.