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