message: Constructs new errors instead of reusing
diff: @@ -12,41 +12,32 @@ const contains = (message, targetStrings = []) =>
  message.toLowerCase().indexOf(targetString.toLowerCase()) >= 0)
  );
  -const ERROR_404 = new Error('Not found');
  -ERROR_404.status = 404;
  -
  -const ERROR_401 = new Error('Access denied');
  -ERROR_401.status = 401;
  -
  -const ERROR_504 = new Error;
  -ERROR_504.status = 504;
  -
  export default (err, _req, _res, next) => {
  - let error;
  -
  const errMessage = err.message && err.message.toLowerCase();
  if (contains(errMessage, [
  'not found', // Old-style errors
  "can't find", // New-style errors
  - ])) error = ERROR_404;
  + ])) {
  + const error = new Error('Not found');
  + error.status = 404;
  + error.originalMessage = err.message;
  + error.stack = err.stack;
  + return next(error);
  + }
  if (contains(errMessage, [
  'unauthorized', // Old-style errors
  'access denied', // Old-style errors
  'unable to', // New-style errors
  'requires sign in', // New-style errors
  - ])) error = ERROR_401;
  -
  - if (err.timeout) {
  - error = ERROR_504;
  - error.message = err.message;
  - }
  -
  - if (error) {
  - // Pass along the original stack
  + ])) {
  + const error = new Error('Access denied');
  + error.status = 401;
  + error.originalMessage = err.message;
  error.stack = err.stack;
  + return next(error);
  }
  - return next(error || err);
  + return next(err);
  };
  