A collection of expected errors that can be raised and middleware for handling/responding to them.
- Added #isExternalServiceError.
- Renamed #handleExpectedError to #handleHttpError as it is a better explanation of what it does.
- Added #createExternalServiceError.
- Exported #createHttpError for creating generic expected http errors.
- #createUnauthorizedError now accepts an original error parameter that will be accessible by calling cause() on the error returned from #createUnauthorizedError.
- Unauthorized errors now have the name UnauthorizedError.
- Unauthorized errors now have the message Unauthorized Error.
- handleExpectedError now only sends a response if the headers have not been sent. This is to cater for the use case of an error being raised by a longer running operation that runs on the server but the server has already told the client that everything is ok to aid with performance.
- Updated createNotFoundError to take an error object parameter that will become the cause of not found error returned.
- Added createConflictError.
- Added isConflictError.
- Added the verror dependancy back as it turns out the way verror handles messages is very handy for logging (it concatenates it's causes).
- Added a name property of ServiceUnavailableError to service unavailable errors.
- Added a code property of 503 to service unavailable errors.
- Added the standard bunyan serializers when creating the log object so that error logging provides details, as a side effect req and res objects will also be serialized as per the bunyan standard serializers: https://github.com/trentm/node-bunyan#standard-serializers
- Changed the interface of createServiceUnavailableError to just take a cause
as the thinking is the type of error is descriptive enough. That is any expected error should just be a type wrapper for a cause. Internally it is possible to set a message suce as Service Unavailable Error.
- Removed the reliance on verror as the only thing we were using for was the cause function.
- These changes have only been applied to createSericeUnavailableError for now to see how they sit in the context of an application.
- Removed the usage of rewire as it was not needed and made the tests harder to read.
- Added a 503 Service unavailable error.
- Added logError error middleware.
- Added a 404 Not Found error.
- Added a 401 Unauthorized error.
- Added the middleware function handleExpectedError to deal with the above errors.