Skip to content

Commit d9e5423

Browse files
committed
ADD response to ApiError
1 parent 7dfe373 commit d9e5423

File tree

7 files changed

+8
-0
lines changed

7 files changed

+8
-0
lines changed

src/templates/core/ApiError.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ApiError extends Error {
99
public readonly statusText: string;
1010
public readonly body: any;
1111
public readonly request: ApiRequestOptions;
12+
public readonly response: ApiResult['response'];
1213

1314
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
1415
super(message);
@@ -19,5 +20,6 @@ export class ApiError extends Error {
1920
this.statusText = response.statusText;
2021
this.body = response.body;
2122
this.request = request;
23+
this.response = response;
2224
}
2325
}

src/templates/core/ApiResult.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export type ApiResult = {
66
readonly status: number;
77
readonly statusText: string;
88
readonly body: any;
9+
readonly response: AxiosResponse<any, any>;
910
};

src/templates/core/axios/request.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
8888
status: response.status,
8989
statusText: response.statusText,
9090
body: responseHeader ?? responseBody,
91+
response: response,
9192
};
9293

9394
catchErrorCodes(options, result);

src/templates/core/fetch/request.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
8181
status: response.status,
8282
statusText: response.statusText,
8383
body: responseHeader ?? responseBody,
84+
response: response,
8485
};
8586

8687
catchErrorCodes(options, result);

src/templates/core/node/request.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
8686
status: response.status,
8787
statusText: response.statusText,
8888
body: responseHeader ?? responseBody,
89+
response: response,
8990
};
9091

9192
catchErrorCodes(options, result);

src/templates/core/xhr/request.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
8484
status: response.status,
8585
statusText: response.statusText,
8686
body: responseHeader ?? responseBody,
87+
response: response,
8788
};
8889

8990
catchErrorCodes(options, result);

test/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
525525
status: response.status,
526526
statusText: response.statusText,
527527
body: responseHeader ?? responseBody,
528+
response: response,
528529
};
529530

530531
catchErrorCodes(options, result);

0 commit comments

Comments
 (0)