첫 커밋
This commit is contained in:
17
src/shared/lib/resultify.ts
Normal file
17
src/shared/lib/resultify.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { CBDCAxiosError } from '@/shared/@types/error';
|
||||
|
||||
export const resultify = async <T = any>(promiseObj: AxiosPromise<T>): Promise<T> => {
|
||||
try {
|
||||
const result: any = await promiseObj;
|
||||
return result?.data !== undefined && result?.data !== null ? result.data : result;
|
||||
} catch (error: any) {
|
||||
const axiosError = error as CBDCAxiosError;
|
||||
console.error(
|
||||
`${
|
||||
axiosError.response?.status ? `[${axiosError.response.status}], ` : ''
|
||||
}${JSON.stringify(axiosError.response?.data)}`,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user