Archived
1
0

Improve request error handling

See #1532 for more context.

- Errored JSON requests will get back the error in JSON instead of using
  the status text. This seems better to me because it seems more correct
  to utilize the response body over hijacking the status text. The
  caller is expecting JSON anyway. Worst of all I never actually set the
  status text like I thought I did so it wasn't working to begin with.
- Allow the update error to propagate for JSON update requests. It was
  caught to show the error inline instead of an error page when using
  the update page but for JSON requests it meant there was no error and
  no error code so it looked like it succeeded.
- Make errors for failed requests to GitHub less incomprehensible.
  Previously they would just be the code which is no context at all.
This commit is contained in:
Asher
2020-04-17 14:58:14 -05:00
parent c7753f2cf9
commit 27ba64c7e4
4 changed files with 38 additions and 23 deletions

View File

@ -541,10 +541,10 @@ index eab8591492..26668701f7 100644
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
new file mode 100644
index 0000000000..4f8543d975
index 0000000000..649cf32f0a
--- /dev/null
+++ b/src/vs/server/browser/client.ts
@@ -0,0 +1,266 @@
@@ -0,0 +1,264 @@
+import { Emitter } from 'vs/base/common/event';
+import { URI } from 'vs/base/common/uri';
+import { localize } from 'vs/nls';
@ -720,11 +720,10 @@ index 0000000000..4f8543d975
+ const response = await fetch(normalize(`${options.base}/update/apply`), {
+ headers: { "content-type": "application/json" },
+ });
+ if (response.status !== 200) {
+ throw new Error(response.statusText);
+ }
+
+ const json = await response.json();
+ if (response.status !== 200 || json.error) {
+ throw new Error(json.error || response.statusText);
+ }
+ (services.get(INotificationService) as INotificationService).info(`Updated to ${json.version}`);
+ };
+
@ -734,11 +733,10 @@ index 0000000000..4f8543d975
+ const response = await fetch(normalize(`${options.base}/update`), {
+ headers: { "content-type": "application/json" },
+ });
+ if (response.status !== 200) {
+ throw new Error("unexpected response");
+ }
+
+ const json = await response.json();
+ if (response.status !== 200 || json.error) {
+ throw new Error(json.error || response.statusText);
+ }
+ if (json.isLatest) {
+ return;
+ }