Handle 204 response in delete-project This change causes calls that fail without throwing an exception to no longer display a message below the "Delete Project" itself, but rather shows a new modal window with the details of the error. If a call fails, throwing an exception, the error will be displayed as before. Bug: Issue 379762004 Change-Id: I779361a1f912a7618c26d154cad08adbb53ca2fd
diff --git a/web/gr-delete-repo.ts b/web/gr-delete-repo.ts index 5d1b537..ff4e0d6 100644 --- a/web/gr-delete-repo.ts +++ b/web/gr-delete-repo.ts
@@ -162,18 +162,32 @@ }; return this.plugin .restApi() - .send(this.action.method, endpoint, json) - .then(_ => { - this.plugin.restApi().invalidateReposCache(); - this.deleteRepoModal?.close(); - window.location.href = `${this.getBaseUrl()}/admin/repos`; - }) + .fetch(this.action.method, endpoint, json) + .then(res => this.handleResponse(res)) .catch(e => { - this.error = e; - this.deleteRepoModal?.close(); + this.handleError(e); }); } + private handleError(e: any) { + if (typeof e === "undefined") { + this.error = "Error deleting project"; + } else { + this.error = e + } + this.deleteRepoModal?.close(); + } + + async handleResponse(response: Response | undefined) { + if (response?.ok) { + this.plugin.restApi().invalidateReposCache(); + this.deleteRepoModal?.close(); + window.location.href = `${this.getBaseUrl()}/admin/repos`; + } else { + this.handleError(undefined) + } + } + private getBaseUrl() { return window.CANONICAL_PATH || ''; }