@@ -38,6 +38,7 @@ export type ApiRequestOptions = {
38
38
readonly formData?: Record<string, any>;
39
39
readonly body?: any;
40
40
readonly mediaType?: string;
41
+ readonly responseType?: 'blob';
41
42
readonly responseHeader?: string;
42
43
readonly errors?: Record<number, string>;
43
44
};"
@@ -450,14 +451,16 @@ const getResponseHeader = (response: Response, responseHeader?: string): string
450
451
return undefined;
451
452
};
452
453
453
- const getResponseBody = async (response: Response): Promise<any> => {
454
+ const getResponseBody = async (response: Response, options: ApiRequestOptions ): Promise<any> => {
454
455
if (response.status !== 204) {
455
456
try {
456
457
const contentType = response.headers.get('Content-Type');
457
458
if (contentType) {
458
459
const isJSON = contentType.toLowerCase().startsWith('application/json');
459
460
if (isJSON) {
460
461
return await response.json();
462
+ } else if (options.responseType === 'blob') {
463
+ return await response.blob();
461
464
} else {
462
465
return await response.text();
463
466
}
@@ -508,7 +511,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
508
511
509
512
if (!onCancel.isCancelled) {
510
513
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
511
- const responseBody = await getResponseBody(response);
514
+ const responseBody = await getResponseBody(response, options );
512
515
const responseHeader = getResponseHeader(response, options.responseHeader);
513
516
514
517
const result: ApiResult = {
@@ -2978,6 +2981,7 @@ export type ApiRequestOptions = {
2978
2981
readonly formData?: Record<string, any>;
2979
2982
readonly body?: any;
2980
2983
readonly mediaType?: string;
2984
+ readonly responseType?: 'blob';
2981
2985
readonly responseHeader?: string;
2982
2986
readonly errors?: Record<number, string>;
2983
2987
};"
@@ -3390,14 +3394,16 @@ const getResponseHeader = (response: Response, responseHeader?: string): string
3390
3394
return undefined;
3391
3395
};
3392
3396
3393
- const getResponseBody = async (response: Response): Promise<any> => {
3397
+ const getResponseBody = async (response: Response, options: ApiRequestOptions ): Promise<any> => {
3394
3398
if (response.status !== 204) {
3395
3399
try {
3396
3400
const contentType = response.headers.get('Content-Type');
3397
3401
if (contentType) {
3398
3402
const isJSON = contentType.toLowerCase().startsWith('application/json');
3399
3403
if (isJSON) {
3400
3404
return await response.json();
3405
+ } else if (options.responseType === 'blob') {
3406
+ return await response.blob();
3401
3407
} else {
3402
3408
return await response.text();
3403
3409
}
@@ -3448,7 +3454,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
3448
3454
3449
3455
if (!onCancel.isCancelled) {
3450
3456
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
3451
- const responseBody = await getResponseBody(response);
3457
+ const responseBody = await getResponseBody(response, options );
3452
3458
const responseHeader = getResponseHeader(response, options.responseHeader);
3453
3459
3454
3460
const result: ApiResult = {
0 commit comments