Skip to content

Commit 28dc619

Browse files
handle-blob-response-type (#4)
1 parent 195593f commit 28dc619

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ async function getResponseBody(response: Response): Promise<any> {
22
try {
33
const contentType = response.headers.get('Content-Type');
44
if (contentType) {
5-
const isJSON = contentType.toLowerCase().startsWith('application/json');
5+
6+
const jsonTypes = ['application/json', 'application/problem+json']
7+
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
8+
9+
//Check for the blob types
10+
const blobTypes = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
11+
const isBlob = blobTypes.some(type => contentType.toLowerCase().startsWith(type));
12+
613
if (isJSON) {
7-
return await response.json();
14+
return await response.json();
15+
} else if (isBlob) {
16+
return await response.arrayBuffer();
817
} else {
918
return await response.text();
1019
}
@@ -13,4 +22,4 @@ async function getResponseBody(response: Response): Promise<any> {
1322
console.error(error);
1423
}
1524
return null;
16-
}
25+
}

0 commit comments

Comments
 (0)