fix react query bug
This commit is contained in:
parent
81eb55e2e0
commit
9b3c1fb49b
|
|
@ -34,10 +34,10 @@ function useAxios() {
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
const responseMsg = response?.data?.message;
|
const responseMsg = response?.data?.message;
|
||||||
const method = response.config.method;
|
const method = response.config.method;
|
||||||
|
|
||||||
const key = response.config.headers[HEADER_KEY];
|
const key = response.config.headers[HEADER_KEY];
|
||||||
const isToasted = response.config.headers["X-Custom-Message"];
|
const isToasted = response.config.headers["X-Custom-Message"];
|
||||||
|
|
||||||
const ResponseMessage =
|
const ResponseMessage =
|
||||||
responseMsg || t("validation.the_possess_done_successful");
|
responseMsg || t("validation.the_possess_done_successful");
|
||||||
if (method !== AxiosQueryEnum?.GET) {
|
if (method !== AxiosQueryEnum?.GET) {
|
||||||
|
|
@ -50,13 +50,16 @@ function useAxios() {
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
console.log(error?.response);
|
// Reject errors with non-2xx status codes
|
||||||
|
const status = error?.response?.status;
|
||||||
const status = error?.request?.status;
|
if (status >= 400) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
const errorMsg = error?.response?.data?.error;
|
const errorMsg = error?.response?.data?.error;
|
||||||
const errorField = error?.response?.data;
|
const errorField = error?.response?.data;
|
||||||
const method = error.config.method;
|
const method = error.config.method;
|
||||||
|
|
||||||
if (status === AxiosStatusEnum.VALIDATION) {
|
if (status === AxiosStatusEnum.VALIDATION) {
|
||||||
setValidation(errorMsg ?? errorField);
|
setValidation(errorMsg ?? errorField);
|
||||||
const ErrorKey = Object?.keys(errorMsg)?.[0];
|
const ErrorKey = Object?.keys(errorMsg)?.[0];
|
||||||
|
|
@ -65,8 +68,6 @@ function useAxios() {
|
||||||
? errorMsg
|
? errorMsg
|
||||||
: errorMsg?.[ErrorKey]?.[0] ??
|
: errorMsg?.[ErrorKey]?.[0] ??
|
||||||
t("validation.some_thing_went_wrong");
|
t("validation.some_thing_went_wrong");
|
||||||
console.log(isString);
|
|
||||||
|
|
||||||
toast.error(t(`${isString}`));
|
toast.error(t(`${isString}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -74,14 +75,17 @@ function useAxios() {
|
||||||
logout();
|
logout();
|
||||||
navigate("/auth");
|
navigate("/auth");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method !== AxiosQueryEnum?.GET) {
|
if (method !== AxiosQueryEnum?.GET) {
|
||||||
const errorMessage = errorMsg || t("validation.some_thing_went_wrong");
|
const errorMessage = errorMsg || t("validation.some_thing_went_wrong");
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
return Promise.reject(error); // Important to reject the promise
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return build_Axios;
|
return build_Axios;
|
||||||
|
|
||||||
// return buildAxios.build();
|
// return buildAxios.build();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user