From cdc67e609dbd20a23ec5ecf2b8ce0101f95dd8ba Mon Sep 17 00:00:00 2001 From: Amio Date: Fri, 3 Aug 2018 21:52:32 +0800 Subject: [PATCH] feat: improve error status --- libs/live-badge-handlers.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/live-badge-handlers.js b/libs/live-badge-handlers.js index b179331..bb077a9 100644 --- a/libs/live-badge-handlers.js +++ b/libs/live-badge-handlers.js @@ -26,11 +26,16 @@ async function fetchLiveParams (scope, fn, paramsPath) { console.time(fetchKey) waitings[fetchKey] = fn(...paramsPath.split('/')).catch(e => { - console.error(fetchKey, 'LIVE_ERROR', e.message) - return { - failed: true, - status: e.code === 'ECONNABORTED' ? 'timeout' : 'unknown' + let status = 'unknown' + + if (e.response && e.response.status === 404) { + status = 'not found' + } else if (e.code === 'ECONNABORTED') { + status = 'timeout' } + + console.error(fetchKey, `LIVEFN_ERR<${status}>`, e.message) + return { status, failed: true } }).then(result => { console.timeEnd(fetchKey) waitings[fetchKey] = undefined