Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 1x 225x 1x | 'use strict';
const BaseExceptionHandler = use('BaseExceptionHandler');
/**
* This class handles all exceptions thrown during
* the HTTP request lifecycle.
*
* @class ExceptionHandler
*/
class ExceptionHandler extends BaseExceptionHandler {
/**
* Handle exception thrown during the HTTP lifecycle
*
* @method handle
*
* @param {Object} error
* @param {Object} options.request
* @param {Object} options.response
*
* @return {void}
*/
async handle(error, { request, response, antl }) {
response.status(error.status).send({
statusCode: error.status,
error: error.name,
message: antl.get(error.message, error.message),
data: error.data || [],
});
}
/**
* Report exception for logging or debugging.
*
* @method report
*
* @param {Object} error
* @param {Object} options.request
*
* @return {void}
*/
/* istanbul ignore next */
async report(_, __) {
/**
* write logger only when enabled for current NODE_ENV
*/
// const env = Config.get('app.http.loggerEnv');
// const NODE_ENV = Env.get('NODE_ENV');
// if (!Array.isArray(env) || env.indexOf(NODE_ENV) > -1) {
// const url = request.url();
// const method = request.method();
// const stack = error.stack
// ? error.stack
// : error.message
// ? error.message
// : error;
// const diff = process.hrtime(request.startTime);
// const ms = prettyMs((diff[0] * 1e9 + diff[1]) / 1e6);
// Logger.error(error.message, {
// level: 'error',
// duration: ms,
// statusCode: error.status,
// requestInfo: {
// method: method,
// url: url,
// data: request.all(),
// headers: request.headers(),
// },
// stack: stack,
// originalError: error,
// });
// }
}
}
module.exports = ExceptionHandler;
|