Skip to content

Commit 5de13b2

Browse files
fcollonvalmeeseeksmachine
authored andcommitted
Backport PR #650: Test for response.ok not status === 200
1 parent e2c7dee commit 5de13b2

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
@@ -262,7 +262,7 @@ export class GitExtension implements IGitExtension {
262262
const response = await httpGitRequest('/git/add_all_unstaged', 'POST', {
263263
top_repo_path: path
264264
});
265-
if (response.status !== 200) {
265+
if (!response.ok) {
266266
const data = await response.json();
267267
throw new ServerConnection.ResponseError(response, data.message);
268268
}
@@ -297,7 +297,7 @@ export class GitExtension implements IGitExtension {
297297
const response = await httpGitRequest('/git/add_all_untracked', 'POST', {
298298
top_repo_path: path
299299
});
300-
if (response.status !== 200) {
300+
if (!response.ok) {
301301
const data = await response.json();
302302
throw new ServerConnection.ResponseError(response, data.message);
303303
}
@@ -358,9 +358,9 @@ export class GitExtension implements IGitExtension {
358358
url,
359359
name
360360
});
361-
if (response.status !== 200) {
362-
const data = await response.text();
363-
throw new ServerConnection.ResponseError(response, data);
361+
if (!response.ok) {
362+
const data = await response.json();
363+
throw new ServerConnection.ResponseError(response, data.message);
364364
}
365365
} catch (err) {
366366
throw new ServerConnection.NetworkError(err);
@@ -390,9 +390,9 @@ export class GitExtension implements IGitExtension {
390390
current_path: path,
391391
history_count: historyCount
392392
});
393-
if (response.status !== 200) {
394-
const data = await response.text();
395-
throw new ServerConnection.ResponseError(response, data);
393+
if (!response.ok) {
394+
const data = await response.json();
395+
throw new ServerConnection.ResponseError(response, data.message);
396396
}
397397
return response.json();
398398
} catch (err) {
@@ -449,7 +449,7 @@ export class GitExtension implements IGitExtension {
449449

450450
try {
451451
const response = await httpGitRequest('/git/checkout', 'POST', body);
452-
if (response.status !== 200) {
452+
if (!response.ok) {
453453
return response.json().then((data: any) => {
454454
throw new ServerConnection.ResponseError(response, data.message);
455455
});
@@ -487,7 +487,7 @@ export class GitExtension implements IGitExtension {
487487
};
488488

489489
const response = await httpGitRequest('/git/clone', 'POST', obj);
490-
if (response.status !== 200) {
490+
if (!response.ok) {
491491
const data = await response.json();
492492
throw new ServerConnection.ResponseError(response, data.message);
493493
}
@@ -522,7 +522,7 @@ export class GitExtension implements IGitExtension {
522522
commit_msg: message,
523523
top_repo_path: path
524524
});
525-
if (response.status !== 200) {
525+
if (!response.ok) {
526526
return response.json().then((data: any) => {
527527
throw new ServerConnection.ResponseError(response, data.message);
528528
});
@@ -600,7 +600,7 @@ export class GitExtension implements IGitExtension {
600600
commit_id: commitId,
601601
top_repo_path: path
602602
});
603-
if (response.status !== 200) {
603+
if (!response.ok) {
604604
return response.json().then((data: any) => {
605605
throw new ServerConnection.ResponseError(response, data.message);
606606
});
@@ -634,7 +634,7 @@ export class GitExtension implements IGitExtension {
634634
selected_hash: hash,
635635
current_path: path
636636
});
637-
if (response.status !== 200) {
637+
if (!response.ok) {
638638
const data = await response.json();
639639
throw new ServerConnection.ResponseError(response, data.message);
640640
}
@@ -685,7 +685,7 @@ export class GitExtension implements IGitExtension {
685685
const response = await httpGitRequest('/git/init', 'POST', {
686686
current_path: path
687687
});
688-
if (response.status !== 200) {
688+
if (!response.ok) {
689689
return response.json().then((data: any) => {
690690
throw new ServerConnection.ResponseError(response, data.message);
691691
});
@@ -717,7 +717,7 @@ export class GitExtension implements IGitExtension {
717717
current_path: path,
718718
history_count: historyCount
719719
});
720-
if (response.status !== 200) {
720+
if (!response.ok) {
721721
const data = await response.json();
722722
throw new ServerConnection.ResponseError(response, data.message);
723723
}
@@ -761,7 +761,7 @@ export class GitExtension implements IGitExtension {
761761
};
762762

763763
const response = await httpGitRequest('/git/pull', 'POST', obj);
764-
if (response.status !== 200) {
764+
if (!response.ok) {
765765
const data = await response.json();
766766
throw new ServerConnection.ResponseError(response, data.message);
767767
}
@@ -793,7 +793,7 @@ export class GitExtension implements IGitExtension {
793793
};
794794

795795
const response = await httpGitRequest('/git/push', 'POST', obj);
796-
if (response.status !== 200) {
796+
if (!response.ok) {
797797
const data = await response.json();
798798
throw new ServerConnection.ResponseError(response, data.message);
799799
}
@@ -849,7 +849,7 @@ export class GitExtension implements IGitExtension {
849849
current_path: path
850850
});
851851
const data = await response.json();
852-
if (response.status !== 200) {
852+
if (!response.ok) {
853853
console.error(data.message);
854854
// TODO should we notify the user
855855
this._setStatus([]);
@@ -895,7 +895,7 @@ export class GitExtension implements IGitExtension {
895895
filename: filename === undefined ? null : filename,
896896
top_repo_path: path
897897
});
898-
if (response.status !== 200) {
898+
if (!response.ok) {
899899
return response.json().then((data: any) => {
900900
throw new ServerConnection.ResponseError(response, data.message);
901901
});
@@ -935,7 +935,7 @@ export class GitExtension implements IGitExtension {
935935
commit_id: commitId,
936936
top_repo_path: path
937937
});
938-
if (response.status !== 200) {
938+
if (!response.ok) {
939939
return response.json().then((data: any) => {
940940
throw new ServerConnection.ResponseError(response, data.message);
941941
});
@@ -956,7 +956,7 @@ export class GitExtension implements IGitExtension {
956956
const response = await httpGitRequest('/git/show_prefix', 'POST', {
957957
current_path: path
958958
});
959-
if (response.status !== 200) {
959+
if (!response.ok) {
960960
const data = await response.json();
961961
throw new ServerConnection.ResponseError(response, data.message);
962962
}
@@ -972,7 +972,7 @@ export class GitExtension implements IGitExtension {
972972
const response = await httpGitRequest('/git/show_top_level', 'POST', {
973973
current_path: path
974974
});
975-
if (response.status !== 200) {
975+
if (!response.ok) {
976976
const data = await response.json();
977977
throw new ServerConnection.ResponseError(response, data.message);
978978
}
@@ -1002,7 +1002,7 @@ export class GitExtension implements IGitExtension {
10021002
const response = await httpGitRequest('/git/branch', 'POST', {
10031003
current_path: path
10041004
});
1005-
if (response.status !== 200) {
1005+
if (!response.ok) {
10061006
const data = await response.json();
10071007
throw new ServerConnection.ResponseError(response, data.message);
10081008
}

0 commit comments

Comments
 (0)