Skip to content

Commit 8054420

Browse files
feat(response): basic support for blob responses
1 parent 3c4376f commit 8054420

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ export const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
6+
const jsonTypes = ['application/json', 'application/problem+json'];
7+
const binaryTypes = ['audio/', 'image/', 'video/'];
78
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
9+
const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
810
if (isJSON) {
911
return await response.json();
12+
} else if (isBinary) {}
13+
return await response.blob();
1014
} else {
1115
return await response.text();
1216
}

src/templates/core/node/getResponseBody.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ export const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
6+
const jsonTypes = ['application/json', 'application/problem+json'];
7+
const binaryTypes = ['audio/', 'image/', 'video/'];
78
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
9+
const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
810
if (isJSON) {
911
return await response.json();
12+
} else if (isBinary) {}
13+
return await response.blob();
1014
} else {
1115
return await response.text();
1216
}

src/templates/core/xhr/getResponseBody.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const getResponseBody = (xhr: XMLHttpRequest): any => {
33
try {
44
const contentType = xhr.getResponseHeader('Content-Type');
55
if (contentType) {
6-
const jsonTypes = ['application/json', 'application/problem+json']
6+
const jsonTypes = ['application/json', 'application/problem+json'];
77
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
88
if (isJSON) {
99
return JSON.parse(xhr.responseText);

0 commit comments

Comments
 (0)