Skip to content

Commit

Permalink
fix: http service transform response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kenso312 committed Feb 3, 2023
1 parent 3c81997 commit a5e9556
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/modules/http/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class HttpService {

instance.defaults.transformResponse = (response: string) => {
try {
return JSON.parse(response).data || response;
const parsedRes = JSON.parse(response);
return parsedRes.data || parsedRes || {};
} catch (error) {
return response;
}
Expand All @@ -46,8 +47,8 @@ export class HttpService {
return response;
},
// Any status codes that falls outside the range of 2xx cause this function to trigger
(error: AxiosError) => {
if ((error as any)?.errno === ECONNREFUSED * -1)
(error: AxiosError & { errno?: number }) => {
if (error?.errno === ECONNREFUSED * -1)
throw NormalException.HTTP_REQUEST_TIMEOUT();

if (error?.response?.data) this.logger.debug(error.response.data);
Expand Down

0 comments on commit a5e9556

Please sign in to comment.