Async Await을 이용하여 처리시 catch를 처리하지 않아 response 무한 대기 현상 해결 방법
Reading time ~1 minute 개인적으로 Promise, callback 보다는 async await를 많이 이용한다. 이와 같이 처리시 기본적으로는 큰 문제가 없지만, callPromiseObject() 를 실행하다 오류가 발생하면 response를 전송하지 못하여 무한 대기 하는 오류가 발생한다. 해결하는 방법은 몇가지가 있는데, 그중 하나는 이와 같이 try, catch를 이용하는 것이다. 개인적으로 동일한 코드가 계속 반복되어 좋아하는 스타일은 아니다.
https://lahuman.github.io/async_await_catch/

미들웨어 써서 promise response error handling 이 될 수도 있지만
[Node js 오류 모음집] Cannot set headers after they are sent to the client
해결해야될 오류 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client 대충 오류 메세지를 보고 나름대로 해석하자면.. 클라이언트에 정보를 전송한 후에 headers를 설정할 수 없다는 것 같다. 구글신께 이 오류에 대하여 여쭤보니, 가소롭다는 듯이 최상단에서 바로 StackOverFlow 형님을 소개시켜주셨다. SOF형님의 말을 발번역하면 아래와 같다. Express에서의 res 오브젝트는 Node.js의 http.ServerResponse의 서브클래스입니다.
https://velog.io/@kim-macbook/Cannot-set-headers-after-they-are-sent-to-the-client
![[Node js 오류 모음집] Cannot set headers after they are sent to the client](https://www.notion.so/image/https%3A%2F%2Fimages.velog.io%2Fvelog.png?table=block&id=cba2ad9e-6bf5-42b6-a175-7d99a55894e4&cache=v2)
