async
-
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번대 에러를 잡아준다.