user 6 年之前
父节点
当前提交
9eb3f92bd6
共有 3 个文件被更改,包括 17 次插入1 次删除
  1. 8 0
      lib/webclient-fetch.js
  2. 1 1
      lib/webclient-fetch.js.map
  3. 8 0
      src/webclient-fetch.ts

+ 8 - 0
lib/webclient-fetch.js

@@ -19,6 +19,10 @@ class WebClientFetch {
                 fetchOptions.body = options.body;
             }
             const res = yield fetch(options.url, fetchOptions);
+            if (!res.ok) {
+                console.error('HTTP error', res);
+                throw new Error('Error ' + res.status + ' returned from ' + options.url);
+            }
             // console.log('res', res);
             return res.text();
         });
@@ -46,6 +50,10 @@ class WebClientFetch {
                 fetchOptions.body = options.body;
             }
             const res = yield fetch(options.url, fetchOptions);
+            if (!res.ok) {
+                console.error('HTTP error', res);
+                throw new Error('Error ' + res.status + ' returned from ' + options.url);
+            }
             // console.log('res', res);
             return res.json();
         });

文件差异内容过多而无法显示
+ 1 - 1
lib/webclient-fetch.js.map


+ 8 - 0
src/webclient-fetch.ts

@@ -13,6 +13,10 @@ export default class WebClientFetch implements IWebClient {
         }
 
         const res = await fetch(options.url, fetchOptions);
+        if (!res.ok) {
+            console.error('HTTP error', res);
+            throw new Error('Error ' + res.status + ' returned from ' + options.url);
+        }
         // console.log('res', res);
         return res.text();
     }    
@@ -39,6 +43,10 @@ export default class WebClientFetch implements IWebClient {
             fetchOptions.body = options.body;
         }
         const res = await fetch(options.url, fetchOptions);
+        if (!res.ok) {
+            console.error('HTTP error', res);
+            throw new Error('Error ' + res.status + ' returned from ' + options.url);
+        }
         // console.log('res', res);
         return res.json();
     }