Quantcast
Channel: User HMR - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by HMR for express not executing error handling middleware

$
0
0

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 44


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>