1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-10 05:40:06 +00:00

fix(*): handle login required state, fix session creation logic

This commit is contained in:
Krishna Acondy
2020-07-18 15:08:40 +01:00
parent a12244cf78
commit 8bf74d17e9
4 changed files with 47 additions and 33 deletions

View File

@@ -11,7 +11,7 @@ export async function makeRequest<T>(
? (res: Response) => res.json()
: (res: Response) => res.text();
let etag = null;
const result = await fetch(url, request).then((response) => {
const result = await fetch(url, request).then(async (response) => {
if (!response.ok) {
if (response.status === 403) {
const tokenHeader = response.headers.get("X-CSRF-HEADER");
@@ -32,8 +32,15 @@ export async function makeRequest<T>(
return responseTransform(res);
});
}
} else {
const body = await response.text();
return Promise.reject({ status: response.status, body });
}
} else {
if (response.redirected && response.url.includes("SASLogon/login")) {
const body = await response.text();
return Promise.reject({ status: 401, body });
}
etag = response.headers.get("ETag");
return responseTransform(response);
}