added post map interceptor

This commit is contained in:
Fedor Katurov 2021-04-20 16:39:51 +07:00
parent fda24c78b0
commit 9c436d348c
5 changed files with 33 additions and 29 deletions

View file

@ -0,0 +1,14 @@
import { AxiosError } from 'axios';
import { PostMapResponse } from '~/utils/api/types';
export const postMapInterceptor = (res: AxiosError<PostMapResponse>) => {
if (res.response?.data.code) {
return res.response;
}
if (res.response?.data.error) {
throw new Error(res.response?.data.error);
}
throw res;
};