refresh test
This commit is contained in:
@@ -23,16 +23,34 @@ export function useServerMutation<TData, TVariables = unknown>(
|
||||
return useMutation({
|
||||
...mutationOptions,
|
||||
mutationFn: async (variables: TVariables) => {
|
||||
const result = await mutationFn(variables);
|
||||
|
||||
if (!result.success) {
|
||||
if (showErrorToast) {
|
||||
toast.error(result.error.userMessage);
|
||||
try {
|
||||
const result = await mutationFn(variables);
|
||||
|
||||
if (!result.success) {
|
||||
if (showErrorToast) {
|
||||
toast.error(result.error.userMessage);
|
||||
}
|
||||
throw new Error(result.error.userMessage);
|
||||
}
|
||||
throw new Error(result.error.userMessage);
|
||||
|
||||
return result.data;
|
||||
} catch (error: any) {
|
||||
if (error?.response?.status === 401) {
|
||||
try {
|
||||
const errorData = typeof error.response.data === 'string'
|
||||
? JSON.parse(error.response.data)
|
||||
: error.response.data;
|
||||
|
||||
if (errorData?.error === "SESSION_REFRESH_REQUIRED") {
|
||||
const currentUrl = window.location.pathname + window.location.search;
|
||||
window.location.href = `/refresh-session?redirect=${encodeURIComponent(currentUrl)}`;
|
||||
throw new Error("SESSION_REFRESH_REQUIRED");
|
||||
}
|
||||
} catch (parseError) {}
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
return result.data;
|
||||
},
|
||||
onSuccess: (data, variables, context) => {
|
||||
if (showSuccessToast && successMessage) {
|
||||
|
||||
Reference in New Issue
Block a user