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.
feat(autogpt_builder): Improve server error handling in `AutoGPTServerAPI`
Reinier van der Leer39556a71cc9b
diff --git a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts b/rnd/autogpt_builder/src/lib/autogpt_server_api.tsindex 73f26da10a..45da285a7a 100644--- a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts+++ b/rnd/autogpt_builder/src/lib/autogpt_server_api.ts@@ -61,18 +61,23 @@ export default class AutoGPTServerAPI {},body: JSON.stringify(flowCreateBody),});+ const response_data = await response.json();if (!response.ok) {- console.warn("POST /graphs returned non-OK response:", response);- throw new Error(`HTTP error ${response.status}!`)+ console.warn(+ `POST /graphs returned non-OK response:`, response_data.detail, response+ );+ throw new Error(`HTTP error ${response.status}! ${response_data.detail}`)}- return await response.json();+ return response_data;} catch (error) {console.error("Error storing flow:", error);throw error;}}- async executeFlow(flowId: string): Promise<FlowExecuteResponse> {+ async executeFlow(+ flowId: string, inputData: { [key: string]: any } = {}+ ): Promise<FlowExecuteResponse> {const path = `/graphs/${flowId}/execute`;console.debug(`POST ${path}`);try {@@ -81,15 +86,16 @@ export default class AutoGPTServerAPI {headers: {'Content-Type': 'application/json',},- body: JSON.stringify({}),+ body: JSON.stringify(inputData),});+ const response_data = await response.json();if (!response.ok) {console.warn(- `POST /graphs/${flowId}/execute returned non-OK response:`, response+ `POST ${path} returned non-OK response:`, response_data.detail, response);- throw new Error(`HTTP error ${response.status}!`)+ throw new Error(`HTTP error ${response.status}! ${response_data.detail}`)}- return await response.json();+ return response_data;} catch (error) {console.error("Error executing flow:", error);throw error;