Skip to content

Commit

Permalink
EDISUP-19351: follow and process redirect for fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
m-skvortsov committed Jan 24, 2025
1 parent c9d49c8 commit 51c73e9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions db-viewer-ui/src/Domain/ApiBase/ApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class ApiBase {
["Content-Type"]: "application/json",
},
["credentials"]: "same-origin",
redirect: "follow",
};
public prefix: string;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<any> {
Expand All @@ -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;
}
}
}

0 comments on commit 51c73e9

Please sign in to comment.