diff --git a/route/api/index.js b/route/api/index.js index 4d9166d..9c2a0fc 100644 --- a/route/api/index.js +++ b/route/api/index.js @@ -16,12 +16,24 @@ r.use(async (c, n) => { c.obj = {} c.db = await DB.connect() c.chkBody = chkObject.bind(c.request) + + let obj = null try { await n() } catch (err) { console.log(err) - c.obj = resObject(err instanceof APIError ? err.resKey : 'InternalError', err.apiMsg || null, err.msgCode || null) + obj = resObject(err instanceof APIError ? err.resKey : 'InternalError', err.apiMsg || null, err.msgCode || null) } + + if (Object.keys(c.obj).length > 0 && 'status' in c.obj && 'obj' in c.obj) { + c.status = c.obj.status + c.body = c.obj.obj + } + if (obj !== null) { + c.status = obj.status + c.body = obj.obj + } + c.db.release() })