AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): better proxy error logging (#10305)
Ubbe07461a88cf90
diff --git a/autogpt_platform/frontend/src/app/api/proxy/[...path]/route.ts b/autogpt_platform/frontend/src/app/api/proxy/[...path]/route.tsindex 682915ffc2..d6965656e2 100644--- a/autogpt_platform/frontend/src/app/api/proxy/[...path]/route.ts+++ b/autogpt_platform/frontend/src/app/api/proxy/[...path]/route.ts@@ -86,7 +86,7 @@ function createUnsupportedContentTypeResponse("application/x-www-form-urlencoded",],},- { status: 415 }, // Unsupported Media Type+ { status: 415 },);}@@ -110,9 +110,19 @@ function createErrorResponse(error: unknown): NextResponse {// If it's our custom ApiError, preserve the original status and responseif (error instanceof ApiError) {+ return NextResponse.json(error.response || { error: error.message }, {+ status: error.status,+ });+ }++ // For JSON parsing errors, provide more context+ if (error instanceof SyntaxError && error.message.includes("JSON")) {return NextResponse.json(- error.response || { error: error.message, detail: error.message },- { status: error.status },+ {+ error: "Invalid response from backend",+ detail: error.message ?? "Backend returned non-JSON response",+ },+ { status: 502 },);}@@ -121,7 +131,7 @@ function createErrorResponse(error: unknown): NextResponse {error instanceof Error ? error.message : "An unknown error occurred";return NextResponse.json({ error: "Proxy request failed", detail },- { status: 500 }, // Internal Server Error+ { status: 500 },);}diff --git a/autogpt_platform/frontend/src/components/ui/use-toast.tsx b/autogpt_platform/frontend/src/components/ui/use-toast.tsxindex 8903aec12f..284a5a162c 100644--- a/autogpt_platform/frontend/src/components/ui/use-toast.tsx+++ b/autogpt_platform/frontend/src/components/ui/use-toast.tsx@@ -197,9 +197,10 @@ function useToastOnFail() {return React.useCallback((action: string, { rethrow = false }: ToastOnFailOptions = {}) =>(error: any) => {+ const err = error as Error;toast({title: `Unable to ${action}`,- description: (error as Error)?.message ?? "Something went wrong",+ description: err.message ?? "Something went wrong",variant: "destructive",duration: 10000,});@@ -211,4 +212,4 @@ function useToastOnFail() {);}-export { useToast, toast, useToastOnFail };+export { toast, useToast, useToastOnFail };diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/helpers.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/helpers.tsindex b9aead3d7b..5b2bdce9ec 100644--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/helpers.ts+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/helpers.ts@@ -78,7 +78,7 @@ export async function getServerAuthToken(): Promise<string> {error,} = await supabase.auth.getSession();- if (error || !session?.access_token) {+ if (error || !session || !session.access_token) {return "no-token-found";}