File tree Expand file tree Collapse file tree 4 files changed +45
-22
lines changed Expand file tree Collapse file tree 4 files changed +45
-22
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
2
2
const token = await resolve(options, OpenAPI.TOKEN);
3
3
const username = await resolve(options, OpenAPI.USERNAME);
4
4
const password = await resolve(options, OpenAPI.PASSWORD);
5
- const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
5
+ const additionalHeaders = await resolve(options, OpenAPI.HEADERS);
6
6
7
- const headers = new Headers ({
7
+ const defaultHeaders = Object.entries ({
8
8
Accept: 'application/json',
9
- ...defaultHeaders ,
9
+ ...additionalHeaders ,
10
10
...options.headers,
11
- });
11
+ })
12
+ .filter(([key, value]) => isDefined(value))
13
+ .reduce((headers, [key, value]) => ({
14
+ ...headers,
15
+ [key]: value,
16
+ }), {});
17
+
18
+ const headers = new Headers(defaultHeaders);
12
19
13
20
if (isStringWithValue(token)) {
14
21
headers.append('Authorization', `Bearer ${token}`);
Original file line number Diff line number Diff line change @@ -2,13 +2,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
2
2
const token = await resolve(options, OpenAPI.TOKEN);
3
3
const username = await resolve(options, OpenAPI.USERNAME);
4
4
const password = await resolve(options, OpenAPI.PASSWORD);
5
- const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
5
+ const additionalHeaders = await resolve(options, OpenAPI.HEADERS);
6
6
7
- const headers = new Headers ({
7
+ const defaultHeaders = Object.entries ({
8
8
Accept: 'application/json',
9
- ...defaultHeaders ,
9
+ ...additionalHeaders ,
10
10
...options.headers,
11
- });
11
+ })
12
+ .filter(([key, value]) => isDefined(value))
13
+ .reduce((headers, [key, value]) => ({
14
+ ...headers,
15
+ [key]: value,
16
+ }), {});
17
+
18
+ const headers = new Headers(defaultHeaders);
12
19
13
20
if (isStringWithValue(token)) {
14
21
headers.append('Authorization', `Bearer ${token}`);
Original file line number Diff line number Diff line change @@ -2,13 +2,20 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
2
2
const token = await resolve(options, OpenAPI.TOKEN);
3
3
const username = await resolve(options, OpenAPI.USERNAME);
4
4
const password = await resolve(options, OpenAPI.PASSWORD);
5
- const defaultHeaders = await resolve(options, OpenAPI.HEADERS);
5
+ const additionalHeaders = await resolve(options, OpenAPI.HEADERS);
6
6
7
- const headers = new Headers ({
7
+ const defaultHeaders = Object.entries ({
8
8
Accept: 'application/json',
9
- ...defaultHeaders ,
9
+ ...additionalHeaders ,
10
10
...options.headers,
11
- });
11
+ })
12
+ .filter(([key, value]) => isDefined(value))
13
+ .reduce((headers, [key, value]) => ({
14
+ ...headers,
15
+ [key]: value,
16
+ }), {});
17
+
18
+ const headers = new Headers(defaultHeaders);
12
19
13
20
if (isStringWithValue(token)) {
14
21
headers.append('Authorization', `Bearer ${token}`);
Original file line number Diff line number Diff line change 1
1
function getResponseBody(xhr: XMLHttpRequest): any {
2
- try {
3
- const contentType = xhr.getResponseHeader('Content-Type');
4
- if (contentType) {
5
- const isJSON = contentType.toLowerCase().startsWith('application/json');
6
- if (isJSON) {
7
- return JSON.parse(xhr.responseText);
8
- } else {
9
- return xhr.responseText;
2
+ if (xhr.status !== 204) {
3
+ try {
4
+ const contentType = xhr.getResponseHeader('Content-Type');
5
+ if (contentType) {
6
+ const isJSON = contentType.toLowerCase().startsWith('application/json');
7
+ if (isJSON) {
8
+ return JSON.parse(xhr.responseText);
9
+ } else {
10
+ return xhr.responseText;
11
+ }
10
12
}
13
+ } catch (error) {
14
+ console.error(error);
11
15
}
12
- } catch (error) {
13
- console.error(error);
14
16
}
15
17
return null;
16
18
}
You can’t perform that action at this time.
0 commit comments