Browse Source

fix: show [again] error details of an update error message

tophf 5 years ago
parent
commit
dd43b7a880
3 changed files with 6 additions and 6 deletions
  1. 2 0
      src/_locales/en/messages.yml
  2. 2 2
      src/background/utils/update.js
  3. 2 4
      src/common/util.js

+ 2 - 0
src/_locales/en/messages.yml

@@ -205,6 +205,8 @@ filterScopeCode:
 filterScopeName:
   description: Option in dashboard's search scope filter.
   message: Name
+genericError:
+  message: Error
 genericOff:
   description: 'To indicate something is turned off or disabled, similar to "no".'
   message: 'off'

+ 2 - 2
src/background/utils/update.js

@@ -94,8 +94,8 @@ async function downloadUpdate({ props: { id }, meta, custom }) {
     Object.assign(update, {
       message,
       checking,
-      // `null` is sendable in Chrome unlike `undefined`
-      error: error?.url || error || null,
+      error: error ? `${i18n('genericError')} ${error.status}, ${error.url}` : null,
+      // `null` is transferable in Chrome unlike `undefined`
     });
     sendCmd(CMD_SCRIPT_UPDATE, result);
   }

+ 2 - 4
src/common/util.js

@@ -211,7 +211,7 @@ export async function request(url, options = {}) {
     init.headers['Content-Type'] = 'application/json';
     init.body = JSON.stringify(init.body);
   }
-  const result = {};
+  const result = { url, status: -1 };
   try {
     const resp = await fetch(url, init);
     const loadMethod = {
@@ -223,9 +223,7 @@ export async function request(url, options = {}) {
     result.status = resp.status || 200;
     result.headers = resp.headers;
     result.data = await resp[loadMethod]();
-  } catch {
-    result.status = -1;
-  }
+  } catch { /* NOP */ }
   if (result.status < 0 || result.status > 300) throw result;
   return result;
 }