MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / getApiErrorMessage

Function getApiErrorMessage

src/utils/api-error-message.ts:102–146  ·  view source on GitHub ↗
(error: unknown, fallback: string)

Source from the content-addressed store, hash-verified

100 * `HttpError` without a usable body yields `fallback`.
101 */
102export function getApiErrorMessage(error: unknown, fallback: string): string {
103 const body = getApiErrorBody(error);
104
105 if (body && typeof body === "object") {
106 const {
107 message,
108 exception,
109 detail,
110 error: bodyError,
111 } = body as {
112 message?: unknown;
113 exception?: unknown;
114 detail?: unknown;
115 error?: unknown;
116 };
117 if (typeof message === "string" && message) return message;
118 const validationMessage = getValidationDetailMessage(detail);
119 const structuredDetailMessage =
120 detail && typeof detail === "object" && !Array.isArray(detail)
121 ? (detail as { message?: unknown }).message
122 : undefined;
123 const detailMessage =
124 typeof detail === "string" && detail
125 ? detail
126 : validationMessage ||
127 getStructuredDetailErrorsMessage(detail) ||
128 (typeof structuredDetailMessage === "string" &&
129 structuredDetailMessage
130 ? structuredDetailMessage
131 : undefined);
132 if (
133 typeof exception === "string" &&
134 exception &&
135 (!detailMessage || detailMessage === AGENT_SERVER_GENERIC_DETAIL)
136 ) {
137 return exception;
138 }
139 if (detailMessage) return detailMessage;
140 if (typeof bodyError === "string" && bodyError) return bodyError;
141 }
142
143 if (isSdkHttpError(error)) return fallback;
144 if (error instanceof Error && error.message) return error.message;
145 return fallback;
146}
147
148/**
149 * Whether the server answered a failed call: there is a response body, or the

Callers 15

handleDeleteFunction · 0.90
FactoryPageFunction · 0.90
TaskDeliveryFunction · 0.90
TaskStartupProgressFunction · 0.90
handleSubmitFunction · 0.90
handleSubmitFunction · 0.90
LlmSettingsLocalViewFunction · 0.90
handleDeleteFunction · 0.90
handleDeleteFunction · 0.90
handleSubmitFunction · 0.90
AutomationSetupPanelFunction · 0.90

Calls 4

isSdkHttpErrorFunction · 0.90
getApiErrorBodyFunction · 0.85

Tested by 1

toastApiMessageFunction · 0.72