forked from DepartmentOfHealth-htbhf/htbhf-applicant-web-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Error handling
Matt Smith edited this page Jan 24, 2020
·
2 revisions
The application uses Winston to log errors. Uncaught errors are logged and handled by the global error handlers.
The application implements a custom error formatter to help when debugging application logs. The error formatter takes a single options argument with the following properties:
| Property | Type | Description |
|---|---|---|
cause |
Error | A javascript Error object |
message |
string | A custom message to give context to the error |
statusCode |
number | A valid HTTP status code indicating the reason for the error |
An example of using the error formatter in a middleware function:
const { wrapError } = require('./errors')
const myMiddleware = (req, res, next) => {
try {
someOperationThatMightFail()
} catch (error) {
return next(wrapError({
cause: error,
message: 'Error performing my operation that could fail',
statusCode: 500
}))
}
return next()
}