Prevent editor-view navigation when publish fails
The restApiService does not throw errors when a custom errFn is given.
In this case it succeeds and returns undefined. Additionally, when the
scheduler reaches its retry limit it succeeds and returns the last
received Response which will have status error 429.
Google-Bug-Id: b/302587986
Release-Notes: skip
Change-Id: I6c9224434e8504bbc9a0c8a70a0e9f83fa3f3c6c
diff --git a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
index f37a3d9..dc3bf7b 100644
--- a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
+++ b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
@@ -479,6 +479,8 @@
this.showAlert(PUBLISHING_EDIT_MSG);
+ // restApiService has some quirks where it will still call .then() with
+ // undefined or Response status 429 when it hits an error.
this.restApiService
.executeChangeAction(
changeNum,
@@ -488,7 +490,14 @@
{notify: NotifyType.NONE},
handleError
)
- .then(() => {
+ .then(res => {
+ if (
+ res === undefined ||
+ (res instanceof Response && res.status === 429)
+ ) {
+ // In an error case we should not navigate and lose edits.
+ return;
+ }
assertIsDefined(this.change, 'change');
this.getChangeModel().navigateToChangeResetReload();
});