fix api response
This commit is contained in:
parent
4f6d7a771f
commit
989ae620b3
@ -16,12 +16,24 @@ r.use(async (c, n) => {
|
|||||||
c.obj = {}
|
c.obj = {}
|
||||||
c.db = await DB.connect()
|
c.db = await DB.connect()
|
||||||
c.chkBody = chkObject.bind(c.request)
|
c.chkBody = chkObject.bind(c.request)
|
||||||
|
|
||||||
|
let obj = null
|
||||||
try {
|
try {
|
||||||
await n()
|
await n()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(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()
|
c.db.release()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user