@maeum/error-handler
v1.0.0
Published
maeum boilerplate error handler creator
Downloads
97
Readme
@maeum/error-handler
Error hander extension of the Maeum boilerplate.
Table of Contents
Getting Start
npm i @maeum/error-handler --save
How it works?
@maeum/error-handler
create error handler for fastify.setErrorHandler
function.
server.setErrorHandler(
errorHandler([], {
[CE_MAEUM_DEFAULT_ERROR_HANDLER.COMMON]: (req, id, param) => getLocales(req.headers['accept-language']).t(id, param),
[CE_MAEUM_DEFAULT_ERROR_HANDLER.DEFAULT_REST_ERROR]: (req, id, param) => getLocales(req.headers['accept-language']).t(id, param),
}, {
hooks: {
[CE_MAEUM_DEFAULT_ERROR_HANDLER.COMMON]: {
pre: (err: Error & { validation?: ErrorObject[] }, req: FastifyRequest) => {
req.setRequestError(err);
},
},
},
encryptor: (code: string): string => {
if (
config.server.runMode === CE_RUN_MODE.STAGE ||
config.server.runMode === CE_RUN_MODE.PRODUCTION
) {
return encrypt(code);
}
return code;
},
}),
);