Merge branch 'master' into release

This commit is contained in:
Jay 2018-08-17 23:08:35 +08:00
commit dc4cde886f

View File

@ -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()
})