Quantcast
Viewing all articles
Browse latest Browse all 43

Answer by HMR for express not executing error handling middleware

In validateUser I am calling next twice:

  const errors = validate(request.body)  errors.length    ? next(new HttpError(400, 'Invalid user sent', errors))    : next()  next()//do not need this one

Removing that one solved the problem but for good measure I removed the return in newUser:

async function newUser(  request: Request,  response: Response,  next: NextFunction) {  try {    const user = await createUser(request.body)    return response.status(201).json(user)  } catch (err) {    console.log('why not!', err)//I can see this log    //return next(err)    next(err)  }}

Viewing all articles
Browse latest Browse all 43

Trending Articles