UNPKG

@tanstack/ai

Version:

Core TanStack AI library - Open source AI SDK

44 lines (43 loc) 1.33 kB
const ABORT_ERROR_NAMES = /* @__PURE__ */ new Set([ "AbortError", "APIUserAbortError", "RequestAbortedError" ]); function normalizeCode(codeField) { if (typeof codeField === "string") return codeField; if (typeof codeField === "number" && Number.isFinite(codeField)) { return String(codeField); } return void 0; } function toRunErrorPayload(error, fallbackMessage = "Unknown error occurred") { if (error && typeof error === "object") { const name = error.name; if (typeof name === "string" && ABORT_ERROR_NAMES.has(name)) { return { message: "Request aborted", code: "aborted" }; } } if (error instanceof Error) { const codeField = error.code; return { message: error.message || fallbackMessage, code: normalizeCode(codeField) }; } if (typeof error === "object" && error !== null) { const messageField = error.message; const codeField = error.code; return { message: typeof messageField === "string" && messageField.length > 0 ? messageField : fallbackMessage, code: normalizeCode(codeField) }; } if (typeof error === "string" && error.length > 0) { return { message: error, code: void 0 }; } return { message: fallbackMessage, code: void 0 }; } export { toRunErrorPayload }; //# sourceMappingURL=error-payload.js.map