Skip to content

Commit

Permalink
fix(provider): better error handling on non provider calls that retur…
Browse files Browse the repository at this point in the history
…ns 404
  • Loading branch information
jigar-arc10 committed Feb 7, 2025
1 parent 17c7ab1 commit e27e54c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions apps/provider-console/src/queries/useProviderQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ import { sanitizeMachineAccess } from "@src/utils/sanityUtils";

type ToastParameters = Omit<ToasterToast, "id">;

const handleQueryError = (
error: AxiosError,
toast: (props: ToastParameters) => unknown,
customMessage?: string,
customTitle = "Uh oh! Something went wrong."
) => {
const handleQueryError = (error: AxiosError, toast: (props: ToastParameters) => unknown, customMessage?: string, customTitle = "Please try again") => {
toast({
variant: "destructive",
title: customTitle,
Expand Down Expand Up @@ -106,7 +101,12 @@ export const useProviderDetails = (address: string | undefined) => {
try {
return await consoleClient.get(`/v1/providers/${address}`);
} catch (error: unknown) {
return handleQueryError(error as AxiosError, toast, "Failed to fetch provider details");
const axiosError = error as AxiosError;
// Don't show toast for 404 errors as it's an expected response for non-providers
if (axiosError.response?.status === 404) {
throw error;
}
return handleQueryError(axiosError, toast, "Failed to fetch provider details");
}
},
refetchOnWindowFocus: false,
Expand All @@ -129,11 +129,22 @@ export const useProviderDashboard = (address: string | undefined) => {
try {
return await consoleClient.get(`/internal/provider-dashboard/${address}`);
} catch (error: unknown) {
return handleQueryError(error as AxiosError, toast, "Failed to fetch provider dashboard");
const axiosError = error as AxiosError;
// Don't show toast for 404 errors as it's an expected response for non-providers
if (axiosError.response?.status === 404) {
throw error;
}
return handleQueryError(axiosError, toast, "Failed to fetch provider dashboard");
}
},
refetchOnWindowFocus: false,
retry: 3,
retry: (failureCount, error: AxiosError) => {
const status = error.response?.status;
if (status && status >= 400 && status < 500) {
return false;
}
return failureCount < 3;
},
enabled: !!address
});
};
Expand Down

0 comments on commit e27e54c

Please sign in to comment.