MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / formatKiloChatError

Function formatKiloChatError

packages/kilo-chat/src/errors.ts:26–45  ·  view source on GitHub ↗
(err: unknown, fallback: string)

Source from the content-addressed store, hash-verified

24 | { kind: 'title-too-long'; limit: number }
25 | { kind: 'message-empty' }
26 | { kind: 'server'; message: string }
27 | { kind: 'fallback' };
28
29/**
30 * Classify an error thrown by `KiloChatClient`.
31 *
32 * - Non-{@link KiloChatApiError} (network/abort/timeout) → `fallback`.
33 * - 401/403 → `not-allowed` (avoids leaking server phrasing).
34 * - 4xx with a zod `issues` array → classify the first known issue; otherwise
35 * surface the server's `error` string when present as `server`.
36 * - 5xx / unknown → `fallback`.
37 *
38 * Callers that need custom branching (e.g. 409 edit conflicts) should check
39 * `err instanceof KiloChatApiError` themselves before delegating here.
40 */
41export function classifyKiloChatError(err: unknown): KiloChatErrorKind {
42 if (!(err instanceof KiloChatApiError)) return { kind: 'fallback' };
43
44 if (err.status === 401 || err.status === 403) return { kind: 'not-allowed' };
45 if (err.status >= 500) return { kind: 'fallback' };
46
47 const body = err.body;
48 if (!body || typeof body !== 'object') return { kind: 'fallback' };

Callers 11

MessageAreaFunction · 0.90
handleRenameKeyDownFunction · 0.90
handleRenameBlurFunction · 0.90
KiloChatLayoutFunction · 0.90
useCreateConversationFunction · 0.90
useRenameConversationFunction · 0.90
useLeaveConversationFunction · 0.90
useSendMessageFunction · 0.90

Calls 1

phraseIssueFunction · 0.85

Tested by

no test coverage detected