|
1 | 1 | {{>header}}
|
| 2 | + |
2 | 3 | import axios from 'axios';
|
3 | 4 | import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
|
4 | 5 | import FormData from 'form-data';
|
@@ -100,16 +101,16 @@ const jar = new CookieJar();
|
100 | 101 | axios.interceptors.response.use((response) => {
|
101 | 102 | if (Array.isArray(response.headers["set-cookie"])) {
|
102 | 103 | response.headers["set-cookie"].forEach((c) => {
|
103 |
| - jar.setCookie(new URL(response.config.url), c); |
| 104 | + jar.setCookie(new URL(response.config.url!), c); |
104 | 105 | });
|
105 | 106 | }
|
106 | 107 | return response;
|
107 | 108 | });
|
108 | 109 |
|
109 | 110 | axios.interceptors.request.use(function (config) {
|
110 |
| - const cookies = jar.getCookies(new URL(config.url)); |
| 111 | + const cookies = jar.getCookies(new URL(config.url!)); |
111 | 112 |
|
112 |
| - if (cookies?.length > 0) { |
| 113 | + if (cookies?.length > 0 && config.headers) { |
113 | 114 | config.headers.cookie = cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
|
114 | 115 | }
|
115 | 116 | return config;
|
@@ -196,10 +197,10 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
|
196 | 197 |
|
197 | 198 | catchErrorCodes(options, result);
|
198 | 199 |
|
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; |
203 | 204 |
|
204 | 205 | resolve(out);
|
205 | 206 | }
|
|
0 commit comments