全局处理异常:
https://blog.csdn.net/weixin_44867717/article/details/131949819
在函数内部处理:
router.post('/:tick', async(ctx, next) => { // 特定tick const params = ctx.request.params; const ids = params.tick let sql = ` SELECT src20_tick_v4.*, src20_mint_progress_v4.* FROM ${SRC20_TICK_TABLE} s, ${SRC20_MINT_PROGRESS_TABLE} WHERE s.id=src20_mint_progress_v4.id and src20_tick_v4.id='${ids}' ` let res = [] try { res = await knex.raw(sql).asCallback(function(err) { if (err) { // console.log(false, err, err.message); // ctx.body = fail(err.message); // throw err; // console.log(false, err); } else { // console.log(true); const resMap = [] for (let each of res.rows) { resMap.push({ tick: each.tick, stamp_url: each.stamp_url, max: each.max ? each.max : "", lim: each.lim ? each.lim : "", amt: new Decimal(each.amt), dec: each.dec ? each.dec : 18, creator: each.creator, tx_hash: each.tx_hash, block_index: each.block_index, block_time: each.block_time, }) } ctx.body = success(resMap.length ? resMap[0] : {}) } }) } catch (e) { // console.log('---------', e.status, e.statusCode, e.message); ctx.body = fail(e.message); } })
sql有问题,被try catch捕获。而不asCallback中的err,但asCallback中的err里包含相同信息。
标签:console,err,koa,src20,ctx,处理,each,tick,异常 From: https://www.cnblogs.com/zccst/p/17926902.html