refactor(llms): split AbortError out of InvokeError

This commit is contained in:
Simon
2026-06-03 23:00:33 +08:00
parent fb8de08c39
commit fd12fb9f1b
4 changed files with 6 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
/**
* Error types and error handling for LLM invocations
* Error types and error handling for LLM invocations.
*/
export const InvokeErrorTypes = {
@@ -14,7 +14,6 @@ export const InvokeErrorTypes = {
UNKNOWN: 'unknown',
// Non-retryable
ABORTED: 'aborted', // User aborted via AbortSignal — instance has name='AbortError'
CONFIG_ERROR: 'config_error', // Invalid local configuration or hook
AUTH_ERROR: 'auth_error', // Authentication failed
CONTEXT_LENGTH: 'context_length', // Prompt too long
@@ -44,9 +43,7 @@ export class InvokeError extends Error {
constructor(type: InvokeErrorType, message: string, rawError?: unknown, rawResponse?: unknown) {
super(message)
// ABORTED conforms to the web platform convention so any consumer using
// `err.name === 'AbortError'` (including native DOMException handlers) Just Works.
this.name = type === InvokeErrorTypes.ABORTED ? 'AbortError' : 'InvokeError'
this.name = 'InvokeError'
this.type = type
this.retryable = RETRYABLE_TYPES.includes(type)
this.rawError = rawError