feat: Error handling, cache logic (#4127)
This commit is contained in:
parent
2c13d144b3
commit
f22064222b
|
|
@ -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 :)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue