diff --git a/lib/routes/kuaidi100/index.js b/lib/routes/kuaidi100/index.js index c3fa5d95f..9f09c0450 100644 --- a/lib/routes/kuaidi100/index.js +++ b/lib/routes/kuaidi100/index.js @@ -27,12 +27,7 @@ module.exports = async (ctx) => { data = query.data; } } else { - data = [ - { - context: message, - time, - }, - ]; + throw new Error(`[本地]信息有误,请检查后重试:${message}`); } // Maybe we can look into isCheck, condition, and state :) diff --git a/lib/routes/kuaidi100/utils.js b/lib/routes/kuaidi100/utils.js index 0a8062f05..15477446b 100644 --- a/lib/routes/kuaidi100/utils.js +++ b/lib/routes/kuaidi100/utils.js @@ -87,7 +87,7 @@ async function getCompanyList(ctx) { list = JSON.parse(list); list = list.company; } catch (e) { - list = []; + throw new Error('无法正确获取快递公司列表:请稍后重试'); } ctx.cache.set(key, list); @@ -201,16 +201,21 @@ module.exports = { }); query = queryResponse.data; - if (query.ischeck === '0' && query.status === '200') { - // Not yet complete, don't cache for now. - // Per owner suggestion - } else { - if (query.data[0].context === '查无结果') { + if (query.status === '200') { + if (query.data && query.data[0].context === '查无结果') { // 查无结果 appears when cookie is invaild, force update cookie. clearCookie(ctx); + throw new Error('暂时无法获取快递信息,请稍后重试...'); + } else if (query.ischeck === '0') { + // Not yet complete, don't cache for now. + // To avoid frquent link test when add source, add 180s cache + ctx.cache.set(query_key, query, 180); } else { - ctx.cache.set(query_key, query); // Finished, or error id + ctx.cache.set(query_key, query); // Finished, cache id } + } else { + ctx.cache.set(query_key, query); // Error, cache as well + throw new Error(`[${query.status}]信息有误,请重新检查后订阅:${query.message}`); } } else { query = JSON.parse(query);