Skip to content

Commit 0c446c6

Browse files
authored
Merge pull request #650 from fcollonval/issue642
Test for `response.ok` not `status === 200`
2 parents ec66c24 + a39bdaf commit 0c446c6

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/model.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class GitExtension implements IGitExtension {
259259
const response = await httpGitRequest('/git/add_all_unstaged', 'POST', {
260260
top_repo_path: path
261261
});
262-
if (response.status !== 200) {
262+
if (!response.ok) {
263263
const data = await response.json();
264264
throw new ServerConnection.ResponseError(response, data.message);
265265
}
@@ -294,7 +294,7 @@ export class GitExtension implements IGitExtension {
294294
const response = await httpGitRequest('/git/add_all_untracked', 'POST', {
295295
top_repo_path: path
296296
});
297-
if (response.status !== 200) {
297+
if (!response.ok) {
298298
const data = await response.json();
299299
throw new ServerConnection.ResponseError(response, data.message);
300300
}
@@ -355,9 +355,9 @@ export class GitExtension implements IGitExtension {
355355
url,
356356
name
357357
});
358-
if (response.status !== 200) {
359-
const data = await response.text();
360-
throw new ServerConnection.ResponseError(response, data);
358+
if (!response.ok) {
359+
const data = await response.json();
360+
throw new ServerConnection.ResponseError(response, data.message);
361361
}
362362
} catch (err) {
363363
throw new ServerConnection.NetworkError(err);
@@ -387,9 +387,9 @@ export class GitExtension implements IGitExtension {
387387
current_path: path,
388388
history_count: historyCount
389389
});
390-
if (response.status !== 200) {
391-
const data = await response.text();
392-
throw new ServerConnection.ResponseError(response, data);
390+
if (!response.ok) {
391+
const data = await response.json();
392+
throw new ServerConnection.ResponseError(response, data.message);
393393
}
394394
return response.json();
395395
} catch (err) {
@@ -446,7 +446,7 @@ export class GitExtension implements IGitExtension {
446446

447447
try {
448448
const response = await httpGitRequest('/git/checkout', 'POST', body);
449-
if (response.status !== 200) {
449+
if (!response.ok) {
450450
return response.json().then((data: any) => {
451451
throw new ServerConnection.ResponseError(response, data.message);
452452
});
@@ -484,7 +484,7 @@ export class GitExtension implements IGitExtension {
484484
};
485485

486486
const response = await httpGitRequest('/git/clone', 'POST', obj);
487-
if (response.status !== 200) {
487+
if (!response.ok) {
488488
const data = await response.json();
489489
throw new ServerConnection.ResponseError(response, data.message);
490490
}
@@ -519,7 +519,7 @@ export class GitExtension implements IGitExtension {
519519
commit_msg: message,
520520
top_repo_path: path
521521
});
522-
if (response.status !== 200) {
522+
if (!response.ok) {
523523
return response.json().then((data: any) => {
524524
throw new ServerConnection.ResponseError(response, data.message);
525525
});
@@ -597,7 +597,7 @@ export class GitExtension implements IGitExtension {
597597
commit_id: commitId,
598598
top_repo_path: path
599599
});
600-
if (response.status !== 200) {
600+
if (!response.ok) {
601601
return response.json().then((data: any) => {
602602
throw new ServerConnection.ResponseError(response, data.message);
603603
});
@@ -631,7 +631,7 @@ export class GitExtension implements IGitExtension {
631631
selected_hash: hash,
632632
current_path: path
633633
});
634-
if (response.status !== 200) {
634+
if (!response.ok) {
635635
const data = await response.json();
636636
throw new ServerConnection.ResponseError(response, data.message);
637637
}
@@ -682,7 +682,7 @@ export class GitExtension implements IGitExtension {
682682
const response = await httpGitRequest('/git/init', 'POST', {
683683
current_path: path
684684
});
685-
if (response.status !== 200) {
685+
if (!response.ok) {
686686
return response.json().then((data: any) => {
687687
throw new ServerConnection.ResponseError(response, data.message);
688688
});
@@ -714,7 +714,7 @@ export class GitExtension implements IGitExtension {
714714
current_path: path,
715715
history_count: historyCount
716716
});
717-
if (response.status !== 200) {
717+
if (!response.ok) {
718718
const data = await response.json();
719719
throw new ServerConnection.ResponseError(response, data.message);
720720
}
@@ -758,7 +758,7 @@ export class GitExtension implements IGitExtension {
758758
};
759759

760760
const response = await httpGitRequest('/git/pull', 'POST', obj);
761-
if (response.status !== 200) {
761+
if (!response.ok) {
762762
const data = await response.json();
763763
throw new ServerConnection.ResponseError(response, data.message);
764764
}
@@ -790,7 +790,7 @@ export class GitExtension implements IGitExtension {
790790
};
791791

792792
const response = await httpGitRequest('/git/push', 'POST', obj);
793-
if (response.status !== 200) {
793+
if (!response.ok) {
794794
const data = await response.json();
795795
throw new ServerConnection.ResponseError(response, data.message);
796796
}
@@ -846,7 +846,7 @@ export class GitExtension implements IGitExtension {
846846
current_path: path
847847
});
848848
const data = await response.json();
849-
if (response.status !== 200) {
849+
if (!response.ok) {
850850
console.error(data.message);
851851
// TODO should we notify the user
852852
this._setStatus([]);
@@ -892,7 +892,7 @@ export class GitExtension implements IGitExtension {
892892
filename: filename === undefined ? null : filename,
893893
top_repo_path: path
894894
});
895-
if (response.status !== 200) {
895+
if (!response.ok) {
896896
return response.json().then((data: any) => {
897897
throw new ServerConnection.ResponseError(response, data.message);
898898
});
@@ -932,7 +932,7 @@ export class GitExtension implements IGitExtension {
932932
commit_id: commitId,
933933
top_repo_path: path
934934
});
935-
if (response.status !== 200) {
935+
if (!response.ok) {
936936
return response.json().then((data: any) => {
937937
throw new ServerConnection.ResponseError(response, data.message);
938938
});
@@ -953,7 +953,7 @@ export class GitExtension implements IGitExtension {
953953
const response = await httpGitRequest('/git/show_prefix', 'POST', {
954954
current_path: path
955955
});
956-
if (response.status !== 200) {
956+
if (!response.ok) {
957957
const data = await response.json();
958958
throw new ServerConnection.ResponseError(response, data.message);
959959
}
@@ -969,7 +969,7 @@ export class GitExtension implements IGitExtension {
969969
const response = await httpGitRequest('/git/show_top_level', 'POST', {
970970
current_path: path
971971
});
972-
if (response.status !== 200) {
972+
if (!response.ok) {
973973
const data = await response.json();
974974
throw new ServerConnection.ResponseError(response, data.message);
975975
}
@@ -999,7 +999,7 @@ export class GitExtension implements IGitExtension {
999999
const response = await httpGitRequest('/git/branch', 'POST', {
10001000
current_path: path
10011001
});
1002-
if (response.status !== 200) {
1002+
if (!response.ok) {
10031003
const data = await response.json();
10041004
throw new ServerConnection.ResponseError(response, data.message);
10051005
}

0 commit comments

Comments
 (0)