(error: unknown)
| 151 | * - Native AbortError (thrown by fetch/AI SDK when AbortSignal is triggered) |
| 152 | */ |
| 153 | export function isAbortError(error: unknown): boolean { |
| 154 | if (!(error instanceof Error)) { |
| 155 | return false |
| 156 | } |
| 157 | // Check for our custom abort error message: |
| 158 | // - Exact match: 'Request aborted' |
| 159 | // - With reason: 'Request aborted: <reason>' (from AbortError class) |
| 160 | if ( |
| 161 | error.message === ABORT_ERROR_MESSAGE || |
| 162 | error.message.startsWith(`${ABORT_ERROR_MESSAGE}: `) |
| 163 | ) { |
| 164 | return true |
| 165 | } |
| 166 | // Check for native AbortError (DOMException or Error with name 'AbortError') |
| 167 | // This is thrown by fetch, AI SDK, and other web APIs when AbortSignal is triggered |
| 168 | if (error.name === 'AbortError') { |
| 169 | return true |
| 170 | } |
| 171 | return false |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Unwrap a PromptResult, returning the value if successful or throwing if aborted. |
no outgoing calls