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

Commit 5b49187

Browse files
committed
Add back changes in 0.23 release that aren't in source
1 parent 936b1d2 commit 5b49187

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/templates/core/axios/request.hbs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{>header}}
2+
23
import axios from 'axios';
34
import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
45
import FormData from 'form-data';
@@ -100,16 +101,16 @@ const jar = new CookieJar();
100101
axios.interceptors.response.use((response) => {
101102
if (Array.isArray(response.headers["set-cookie"])) {
102103
response.headers["set-cookie"].forEach((c) => {
103-
jar.setCookie(new URL(response.config.url), c);
104+
jar.setCookie(new URL(response.config.url!), c);
104105
});
105106
}
106107
return response;
107108
});
108109

109110
axios.interceptors.request.use(function (config) {
110-
const cookies = jar.getCookies(new URL(config.url));
111+
const cookies = jar.getCookies(new URL(config.url!));
111112

112-
if (cookies?.length > 0) {
113+
if (cookies?.length > 0 && config.headers) {
113114
config.headers.cookie = cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
114115
}
115116
return config;
@@ -196,10 +197,10 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
196197

197198
catchErrorCodes(options, result);
198199

199-
// Attach the response headers to the output. This is a hack to fix
200-
// https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1295
201-
const out = result.body;
202-
out["__headers"] = response.headers;
200+
// Attach the response headers to the output. This is a hack to fix
201+
// https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1295
202+
const out = result.body;
203+
out["__headers"] = response.headers;
203204

204205
resolve(out);
205206
}

0 commit comments

Comments
 (0)