case 4311

This commit is contained in:
2022-11-21 23:54:39 +00:00
parent aad5484342
commit 78f8feae21

View File

@@ -305,7 +305,7 @@ async function ayGetFromAPI(route, token) {
Authorization: token Authorization: token
} }
}); });
return await r.json(); return await extractBodyEx(r);
} catch (error) { } catch (error) {
//fundamental error, can't proceed with this call //fundamental error, can't proceed with this call
// handleError("GET", error, route); // handleError("GET", error, route);
@@ -338,7 +338,7 @@ async function ayPostToAPI(route, data, token) {
body: JSON.stringify(data) body: JSON.stringify(data)
}; };
let r = await fetch(route, fetchOptions); let r = await fetch(route, fetchOptions);
return await r.json(); return await extractBodyEx(r);
} catch (error) { } catch (error) {
throw error; throw error;
} }
@@ -369,7 +369,7 @@ async function ayPutToAPI(route, data, token) {
body: JSON.stringify(data) body: JSON.stringify(data)
}; };
let r = await fetch(route, fetchOptions); let r = await fetch(route, fetchOptions);
return await r.json(); return await extractBodyEx(r);
} catch (error) { } catch (error) {
throw error; throw error;
} }
@@ -398,6 +398,34 @@ function attachmentDownloadUrl(fileId, ctype) {
//##################################### CODE UTILITIES ################################################### //##################################### CODE UTILITIES ###################################################
async function extractBodyEx(response) {
if (response.status == 204) {
//no content, nothing to process
return response;
}
if (response.status == 202) {
//Accepted, nothing to process
return response;
}
const contentType = response.headers.get("content-type");
if (!contentType) {
return response;
}
if (contentType.includes("json")) {
return await response.json();
}
if (contentType.includes("text/plain")) {
return await response.text();
}
if (contentType.includes("application/pdf")) {
return await response.blob();
}
return response;
}
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// Group by function // Group by function
// reshapes input array into a new array grouped with // reshapes input array into a new array grouped with