Function: errorBodyMessage()
errorBodyMessage(
body):string|undefined
Defined in: index.ts:252
The message an error body carries, across the two shapes REST APIs answer
with: { error: 'text' } and { error: { code?, message? } }.
The structured one is why this is read rather than taken: an object handed
to new Error() renders as [object Object], and inside a tool handler
that string is the whole answer the calling model acts on.
Exported so a tool handler with its own HTTP client renders error bodies
exactly as apiCall does. Returns undefined when the body carries no
message.
Parameters
| Parameter | Type |
|---|---|
body | unknown |
Returns
string | undefined
Example
if (!response.ok) {
const body = await response.json().catch(() => undefined);
throw new Error(errorBodyMessage(body) ?? `HTTP ${response.status}`);
}