Open expelliamus opened 4 years ago
Restify handles errors differently that express and doesn't use a middleware. (See the docs for this here)
Here is how I handle my errors:
class ErrorHandler {
constructor(server) {
server.on(`restifyError`, this.defaultErrorHandler);
}
defaultErrorHandler(req, res, err, callback) {
console.error(err);
return callback();
}
}
const { createServer } = require(`restify`);
const { ErrorHandler } = require(`./ErrorHandler.js`);
const server = createServer();
new ErrorHandler(server);
@reediculous456 I understand but is not what I asked for... suppose you have this:
server.post('/customers', customerService.create);
then you have this:
export const create = async (req: Request, res: Response): Promise<Customer> => {
throw new Error('Promise rejection error');
none of the following will handle the promise rejection:
server.on(`restifyError`, this.defaultErrorHandler);
server.on(`InternalServer`, this.defaultErrorHandler);
so Restify doesn't provide any way to handle Promise Rejection and this is bad
Restify 8 does not support promises as route handlers. Restify 9 will, support is already integrated on master
: https://github.com/restify/node-restify/pull/1833
@mmarchini do you know of an ETA for v9?
My application heavily depends on that. Any schedule/ETA?
If not, is the current master
branch stable? If so, I'd reference this in my package.json
.
I'm trying to handle promise rejection creating a simple middleware, so I did:
so:
but surprising I get:
so
Restify
does not includeError
, and for manage the Promise rejection I should wrap this around each route:this could become a pain, why Restify doesn't support Error in RequestHandler?