File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,14 @@ export const getResponseBody = async (response: Response): Promise<any> => {
3
3
try {
4
4
const contentType = response.headers.get('Content-Type');
5
5
if (contentType) {
6
- const jsonTypes = ['application/json', 'application/problem+json']
6
+ const jsonTypes = ['application/json', 'application/problem+json'];
7
+ const binaryTypes = ['audio/', 'image/', 'video/'];
7
8
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
9
+ const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
8
10
if (isJSON) {
9
11
return await response.json();
12
+ } else if (isBinary) {}
13
+ return await response.blob();
10
14
} else {
11
15
return await response.text();
12
16
}
Original file line number Diff line number Diff line change @@ -3,10 +3,14 @@ export const getResponseBody = async (response: Response): Promise<any> => {
3
3
try {
4
4
const contentType = response.headers.get('Content-Type');
5
5
if (contentType) {
6
- const jsonTypes = ['application/json', 'application/problem+json']
6
+ const jsonTypes = ['application/json', 'application/problem+json'];
7
+ const binaryTypes = ['audio/', 'image/', 'video/'];
7
8
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
9
+ const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
8
10
if (isJSON) {
9
11
return await response.json();
12
+ } else if (isBinary) {}
13
+ return await response.blob();
10
14
} else {
11
15
return await response.text();
12
16
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ export const getResponseBody = (xhr: XMLHttpRequest): any => {
3
3
try {
4
4
const contentType = xhr.getResponseHeader('Content-Type');
5
5
if (contentType) {
6
- const jsonTypes = ['application/json', 'application/problem+json']
6
+ const jsonTypes = ['application/json', 'application/problem+json'];
7
7
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
8
8
if (isJSON) {
9
9
return JSON.parse(xhr.responseText);
You can’t perform that action at this time.
0 commit comments