@@ -82,8 +82,6 @@ export class BaseClient extends Client {
8282
8383 const { body, contentType } = this . prepareBodyPayload ( request ) ;
8484
85- // console.log('content-type', contentType);
86-
8785 const config : RequestInit = {
8886 method : request . method ,
8987 headers : this . removeUndefinedProperties ( {
@@ -98,9 +96,6 @@ export class BaseClient extends Client {
9896 body,
9997 } ;
10098
101- // console.log(url.toString());
102- // console.log(config);
103-
10499 const response = await fetch ( url , config ) ;
105100
106101 if ( ! response . ok ) {
@@ -116,63 +111,16 @@ export class BaseClient extends Client {
116111 if ( contentType . includes ( 'application/json' ) ) {
117112 const json = await response . json ( ) ;
118113
119- throw new Error ( JSON . stringify ( json ) ) ;
114+ throw new Error ( JSON . stringify ( json ) ) ; // todo error handling
120115 }
121116
122117 const errorMessage = await response . text ( ) ;
123118
124- console . error ( response . status ) ;
125- console . error ( response . statusText ) ;
126-
127119 throw new Error ( errorMessage ) ;
128120 }
129121
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 ;
176124 let contentType : string | undefined = request . headers ?. [ 'Content-Type' ] ?? request . headers ?. [ 'content-type' ] ;
177125
178126 if ( request . body instanceof FormData ) {
@@ -189,14 +137,11 @@ export class BaseClient extends Client {
189137 } else if ( typeof request . body === 'string' ) {
190138 body = request . body ;
191139 contentType = 'text/plain' ;
192- } else if ( request . body instanceof URLSearchParams ) {
193- body = request . body . toString ( ) ;
194- contentType = 'application/x-www-form-urlencoded' ;
195140 }
196141
197142 return {
198143 body,
199144 contentType,
200- } ;
145+ } as { body : BodyInit | null | undefined ; contentType : string } ;
201146 }
202147}
0 commit comments