All files / server/boot hook.js

100% Statements 10/10
50% Branches 2/4
100% Functions 2/2
100% Lines 10/10

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 211x 1x   1x 1x   1x 1x     1x 1x 1x             1x  
const uuidv1 = require('uuid/v1');
const logger = require('../../services/logger');
 
module.exports = function(app) {
  const remotes = app.remotes();
 
  remotes.options.rest = remotes.options.rest || {}
  remotes.options.rest.handleErrors = false;
 
  function FinalErrorHandler(err, req, res, next) {
    const errorId = uuidv1();
    logger.error(`Message: ${err.message}, ErrorId: ${errorId}`);
    res.status(err.statusCode).send({
      message: err.message, 
      ErrorId: errorId,
      name: err.name ? err.name : ''
    }).end();
  }
 
  app.middleware('final', FinalErrorHandler);
}