Using conditional error handling based on the current NODE_ENV but code hangs

26 Views Asked by At

So I've made this error handler which ends a different response based on the current node environment but the code hangs in the if statement. Printing process.env.NODE_ENV gives me a value of 'development' or 'production' based on which it is currently set to but the code doesn't seem to recognize it when entering the if statement. If I remove the if statement the code will return the error as expected. Thanks for your help!

module.exports = (err, req, res, next) => {
  // Express knows error middleware because of 4 parameters set
  err.statusCode = err.statusCode || 500; // read status code on object
  // if not defined '500' default
  err.status = err.status || 'error';

  console.log(process.env.NODE_ENV);
  currentMode = process.env.NODE_ENV;
  if (currentMode === 'development') {
    sendErrorDev(err, res);
  } else if {
    (currentMode === 'production') {
       sendErrorProd(err, res);
  }
};
0

There are 0 best solutions below