From 51c73e94645cd05d39debb6687853be679cdbc8b Mon Sep 17 00:00:00 2001 From: "skvortsov.m" Date: Fri, 24 Jan 2025 10:57:52 +0300 Subject: [PATCH] EDISUP-19351: follow and process redirect for fetch --- db-viewer-ui/src/Domain/ApiBase/ApiBase.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/db-viewer-ui/src/Domain/ApiBase/ApiBase.ts b/db-viewer-ui/src/Domain/ApiBase/ApiBase.ts index 58a2e871..072aa0aa 100644 --- a/db-viewer-ui/src/Domain/ApiBase/ApiBase.ts +++ b/db-viewer-ui/src/Domain/ApiBase/ApiBase.ts @@ -22,6 +22,7 @@ export default class ApiBase { ["Content-Type"]: "application/json", }, ["credentials"]: "same-origin", + redirect: "follow", }; public prefix: string; @@ -58,11 +59,15 @@ export default class ApiBase { method: "POST", body: JSON.stringify(body), }); + await this.checkStatus(response); + this.processRedirect(response); + const textResult = await response.text(); if (textResult !== "") { return JSON.parse(textResult); } + return undefined; } @@ -107,9 +112,11 @@ export default class ApiBase { ...ApiBase.additionalHeaders, method: "GET", }); + await this.checkStatus(response); - const result = await response.json(); - return result; + this.processRedirect(response); + + return response.json(); } public async delete(url: string, body: {}): Promise { @@ -118,11 +125,21 @@ export default class ApiBase { method: "DELETE", body: JSON.stringify(body), }); + await this.checkStatus(response); + this.processRedirect(response); + const textResult = await response.text(); if (textResult !== "") { return JSON.parse(textResult); } + return undefined; } + + private processRedirect(response: Response) { + if (response.redirected && response.url) { + location.href = response.url; + } + } }