SHARE
TWEET

Untitled

a guest Jun 25th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { RequestError } = require('../core/models/errors/request-error.model');
  2. const Logger = require('../core/helpers/logger.helper');
  3.  
  4. const errorHandlerMiddleware = (error, request, response, next) => {
  5.   if (error) {
  6.     Logger.stackTrace(error);
  7.     if (error instanceof RequestError) {
  8.       response
  9.       .status(error.statusCode)
  10.       .send(errorResponse);
  11.     }
  12.     // ...
  13.     // Write some custom behaviour related to another errors
  14.     // ...
  15.   } else {
  16.     next(request, response);
  17.   }
  18. };
  19.  
  20. module.exports = errorHandlerMiddleware;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top