Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit d0da436

Browse files
committed
Expose headers for from service in fetch
1 parent 89b8751 commit d0da436

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/templates/core/fetch/request.hbs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,28 @@ import { OpenAPI } from './OpenAPI';
4747
{{>functions/catchErrors}}
4848

4949

50+
interface ApiResultWithHeaders extends ApiResult {
51+
headers: Headers;
52+
}
53+
5054
/**
5155
* Request using fetch client
5256
* @param options The request options from the the service
5357
* @returns ApiResult
5458
* @throws ApiError
5559
*/
56-
export async function request(options: ApiRequestOptions): Promise<ApiResult> {
60+
export async function request(options: ApiRequestOptions): Promise<ApiResultWithHeaders> {
5761
const url = getUrl(options);
5862
const response = await sendRequest(options, url);
5963
const responseBody = await getResponseBody(response);
60-
const responseHeader = getResponseHeader(response, options.responseHeader);
6164

62-
const result: ApiResult = {
65+
const result: ApiResultWithHeaders = {
6366
url,
6467
ok: response.ok,
6568
status: response.status,
6669
statusText: response.statusText,
6770
body: responseHeader || responseBody,
71+
headers: response.headers,
6872
};
6973

7074
catchErrors(options, result);

src/templates/exportService.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class {{{name}}} {
3535
{{/each}}
3636
* @throws ApiError
3737
*/
38-
public static async {{{name}}}({{>parameters}}): Promise<{{>result}}> {
38+
public static async {{{name}}}({{>parameters}}): Promise<{body: {{>result}}; headers: Headers }> {
3939
const result = await __request({
4040
method: '{{{method}}}',
4141
path: `{{{path}}}`,

0 commit comments

Comments
 (0)