-
express async request handler 오류Vue 2021. 1. 26. 17:07
1. sync function의 경우
app.get("/error", (req, res) => { throw "에러" })
정상적으로 에러를 잡아준다.
2. async function의 경우
app.get("/error", async (req, res) => { throw "에러" })
에러를 잡아주지 못한다. async function을 try catch문을 사용하여 에러를 잡아주어야한다.
app.get("/error", async (req, res, next) => { try { throw "에러" } catch (err) { next(err) } })
이런식으로 잡아주면
정상적으로 500번대 에러를 잡아준다.
'Vue' 카테고리의 다른 글
[Vue]record 문법 사용법 (0) 2021.01.06 [Vue3+mongoDB+express ch.4] 라우터 설정 (router) (0) 2020.12.31 [Vue3+mongoDB+express ch.3] Frontend Backend 연결 (0) 2020.12.31 vue3 express mongoDB 개발환경 세팅 (0) 2020.12.29 typescript를 사용한 Vue3 프로젝트 환경 만들기 (0) 2020.12.24