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): fix client side error handling in custom mutator (#11160)
Abhimanyu Yadav63076a67e1c4
diff --git a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.tsindex 347ab30636..17e32256ee 100644--- a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts+++ b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts@@ -1,4 +1,5 @@import {+ ApiError,createRequestHeaders,getServerAuthToken,} from "@/lib/autogpt-server-api/helpers";@@ -93,17 +94,17 @@ export const customMutator = async <body: data,});- // Error handling for server-side requests- // We do not need robust error handling for server-side requests; we only need to log the error message and throw the error.- // What happens if the server-side request fails?- // 1. The error will be logged in the terminal, then.- // 2. The error will be thrown, so the cached data for this particular queryKey will be empty, then.- // 3. The client-side will send the request again via the proxy. If it fails again, the error will be handled on the client side.- // 4. If the request succeeds on the server side, the data will be cached, and the client will use it instead of sending a request to the proxy.-- if (!response.ok && isServerSide()) {- console.error("Request failed on server side", response, fullUrl);- throw new Error(`Request failed with status ${response.status}`);+ if (!response.ok) {+ const response_data = await getBody<any>(response);+ const errorMessage =+ response_data?.detail || response_data?.message || response.statusText;++ console.error(+ `Request failed ${isServerSide() ? "on server" : "on client"}`,+ { status: response.status, url: fullUrl, data: response_data },+ );++ throw new ApiError(errorMessage, response.status, response_data);}const response_data = await getBody<T["data"]>(response);