Skip to content

Commit a5e9556

Browse files
committed
fix: http service transform response handling
1 parent 3c81997 commit a5e9556

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/modules/http/http.service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class HttpService {
2121

2222
instance.defaults.transformResponse = (response: string) => {
2323
try {
24-
return JSON.parse(response).data || response;
24+
const parsedRes = JSON.parse(response);
25+
return parsedRes.data || parsedRes || {};
2526
} catch (error) {
2627
return response;
2728
}
@@ -46,8 +47,8 @@ export class HttpService {
4647
return response;
4748
},
4849
// Any status codes that falls outside the range of 2xx cause this function to trigger
49-
(error: AxiosError) => {
50-
if ((error as any)?.errno === ECONNREFUSED * -1)
50+
(error: AxiosError & { errno?: number }) => {
51+
if (error?.errno === ECONNREFUSED * -1)
5152
throw NormalException.HTTP_REQUEST_TIMEOUT();
5253

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

0 commit comments

Comments
 (0)