@@ -82,8 +82,6 @@ export class BaseClient extends Client {
82
82
83
83
const { body, contentType } = this . prepareBodyPayload ( request ) ;
84
84
85
- // console.log('content-type', contentType);
86
-
87
85
const config : RequestInit = {
88
86
method : request . method ,
89
87
headers : this . removeUndefinedProperties ( {
@@ -98,9 +96,6 @@ export class BaseClient extends Client {
98
96
body,
99
97
} ;
100
98
101
- // console.log(url.toString());
102
- // console.log(config);
103
-
104
99
const response = await fetch ( url , config ) ;
105
100
106
101
if ( ! response . ok ) {
@@ -116,63 +111,16 @@ export class BaseClient extends Client {
116
111
if ( contentType . includes ( 'application/json' ) ) {
117
112
const json = await response . json ( ) ;
118
113
119
- throw new Error ( JSON . stringify ( json ) ) ;
114
+ throw new Error ( JSON . stringify ( json ) ) ; // todo error handling
120
115
}
121
116
122
117
const errorMessage = await response . text ( ) ;
123
118
124
- console . error ( response . status ) ;
125
- console . error ( response . statusText ) ;
126
-
127
119
throw new Error ( errorMessage ) ;
128
120
}
129
121
130
- // handleSuccessResponse<T>(response: any): T {
131
- // this.config.middlewares?.onResponse?.(response.data);
132
- //
133
- // return response;
134
- // }
135
- //
136
- // handleFailedResponse(e: unknown): JiraError {
137
- // const err = this.buildErrorHandlingResponse(e);
138
- //
139
- // this.config.middlewares?.onError?.(err);
140
- //
141
- // return err;
142
- // }
143
- //
144
- // private buildErrorHandlingResponse(e: unknown): JiraError {
145
- // if (axios.isAxiosError(e) && e.response) {
146
- // return new HttpException(
147
- // {
148
- // code: e.code,
149
- // message: e.message,
150
- // data: e.response.data,
151
- // status: e.response.status,
152
- // statusText: e.response.statusText,
153
- // },
154
- // e.response.status,
155
- // { cause: e },
156
- // );
157
- // }
158
- //
159
- // if (axios.isAxiosError(e)) {
160
- // return e;
161
- // }
162
- //
163
- // if (isObject(e) && isObject((e as Record<string, any>).response)) {
164
- // return new HttpException((e as Record<string, any>).response);
165
- // }
166
- //
167
- // if (e instanceof Error) {
168
- // return new HttpException(e);
169
- // }
170
- //
171
- // return new HttpException('Unknown error occurred.', 500, { cause: e });
172
- // }
173
-
174
- private prepareBodyPayload ( request : Request ) {
175
- let body : string | Blob | FormData | ArrayBuffer | undefined = request . body ;
122
+ private prepareBodyPayload ( request : Request ) : { body : BodyInit | null | undefined ; contentType : string | undefined } {
123
+ let body : BodyInit | object | undefined | null = request . body ;
176
124
let contentType : string | undefined = request . headers ?. [ 'Content-Type' ] ?? request . headers ?. [ 'content-type' ] ;
177
125
178
126
if ( request . body instanceof FormData ) {
@@ -189,14 +137,11 @@ export class BaseClient extends Client {
189
137
} else if ( typeof request . body === 'string' ) {
190
138
body = request . body ;
191
139
contentType = 'text/plain' ;
192
- } else if ( request . body instanceof URLSearchParams ) {
193
- body = request . body . toString ( ) ;
194
- contentType = 'application/x-www-form-urlencoded' ;
195
140
}
196
141
197
142
return {
198
143
body,
199
144
contentType,
200
- } ;
145
+ } as { body : BodyInit | null | undefined ; contentType : string } ;
201
146
}
202
147
}
0 commit comments