Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider): better error handling on non provider calls (404 error) #813

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/provider-console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashnetwork/provider-console",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"scripts": {
"build": "npm run build-env-schemas && next build",
Expand Down
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