Error management

Route's internal middleware stack execution works with Promises (bluebirdjs).


//...
const route = router.buildRoute({/*options*/});

route.main(function(req, res) {
    return asyncProcedure();
}).catch(TypeError, function(err) {
    err.message === 'error message'; //true
});

function asyncProcedure() {
    return Promise.reject(new TypeError('error message'));
}

All errors which happen in a request lifecycle get eventually processed by internal errorHandler middleware.
Service App can respond to a request only with an error of type RequestError thus all other errors which don't extend the RequestError are coerced to meet the condition (converted to ServiceError).
All unexpected errors - aka all errors which do NOT inherit RequestError or are instance of ServiceError - trigger App#event:error event on App instance object.
All unexpected errors are logged to configured remote destination by the bi-logger package.
See bi-service ErrorList for the list of built-in Error types.

You can influence the way errors are processed by the following events:

comments powered by Disqus