From 1aa9689b4f5f7df6c653f152ce70a04f8eab7ebe Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 23 Aug 2020 19:21:39 -0700 Subject: [PATCH] Fix crash on invalid data. --- lib/middleware.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 9e46b0c8..5cbe9c2c 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -18,9 +18,13 @@ export function use(middleware) { export const useCors = use(cors()); export const useSession = use(async (req, res, next) => { - const session = await verifySession(req).catch(e => { + let session; + + try { + session = await verifySession(req); + } catch (e) { return serverError(res, e.message); - }); + } if (!session) { return badRequest(res); @@ -31,9 +35,13 @@ export const useSession = use(async (req, res, next) => { }); export const useAuth = use(async (req, res, next) => { - const token = await verifyAuthToken(req).catch(e => { + let token; + + try { + token = await verifyAuthToken(req); + } catch (e) { return serverError(res, e.message); - }); + } if (!token) { return unauthorized(res);