Express.js)Error : Cannot set headers after they are sent to the client

김명성·2022년 6월 26일
0

서버에서 클라이언트단으로 복수의 응답을 보내려고 할 때 발생하는 오류.
return문 없이 next method를 사용하거나,
if, else문으로 조건에 따라 움직임을 명확히 하지 않았을 때 발생한다.

//user-controllers
  if (!identifiedUser || identifiedUser.password !== password) {
    const error = new HttpError(' email or password is invalid. credentials seem to be wrong.', 401)
    //return을 작성하지 않아서 해당 오류가 발생했었음.
    return next(error)
  }
  res.status(200).json({
    message: 'Logged in'
  })

0개의 댓글