Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

default error handler express

app.use((err, req, res, next) => {
  const defaultErr = {
    log: 'Express error handler caught unknown middleware error',
    status: 500,
    message: { err: 'An error occurred' },
  };
  const errorObj = Object.assign({}, defaultErr, err);
  console.log(errorObj.log);
  return res.status(errorObj.status).json(errorObj.message);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: empty body in get request fetch api 
Javascript :: express get request origin 
Javascript :: jest regex jsx tsx js ts 
Javascript :: js switch case 
Javascript :: remove floating point javascript 
Javascript :: java script change url without reload 
Javascript :: object get property with max value javascript 
Javascript :: js inner text 
Javascript :: js revers string fucntion 
Javascript :: how to handle error axios js 
Javascript :: postman scripts check variable exists 
Javascript :: regular expression should not contain special character 
Javascript :: js remove end comma 
Javascript :: casperjs exit 
Javascript :: html2canvas cdn 
Javascript :: how to send post request js fetch 
Javascript :: enable input jquery 
Javascript :: javascript get int val 
Javascript :: curl accept json 
Javascript :: ng serve without reload 
Javascript :: npm ERR! code ELIFECYCLE npm ERR! errno 1 
Javascript :: do more than one thing at start of or loop javascript 
Javascript :: how to zip two arrays in javascript 
Javascript :: js escape ampersand 
Javascript :: hide / show jquery 
Javascript :: jetbrains vscode 
Javascript :: negative number error handling in javascript 
Javascript :: how to pass data between routes in react 
Javascript :: Iterate Odd Numbers With a For Loop 
Javascript :: regex to check if string contains special characters javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =