When defining the variable err
, I have opted to use any
due to uncertainty about the correct type. I was anticipating an express.Error
type, but none was found.
What would be the appropriate way to assign a type to err
?
// Addressing Syntax Error in JSON
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
if (err.status === 400 && err instanceof SyntaxError && 'body' in err) {
res.status(200).send({ message: 'JSON Syntax Error' });
} else {
next();
}
});