File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ export class Stream<Item> extends CoreStream<Item> {
90
90
done = true ;
91
91
} catch ( e ) {
92
92
// If the user calls `stream.controller.abort()`, we should exit without throwing.
93
- if ( e instanceof Error && e . name === 'AbortError' ) return ;
93
+ if ( isAbortError ( e ) ) return ;
94
94
throw e ;
95
95
} finally {
96
96
// If the user `break`s, abort the ongoing request.
@@ -101,3 +101,14 @@ export class Stream<Item> extends CoreStream<Item> {
101
101
return new Stream ( iterator , controller ) ;
102
102
}
103
103
}
104
+
105
+ function isAbortError ( err : unknown ) {
106
+ return (
107
+ typeof err === 'object' &&
108
+ err !== null &&
109
+ // Spec-compliant fetch implementations
110
+ ( ( 'name' in err && ( err as any ) . name === 'AbortError' ) ||
111
+ // Expo fetch
112
+ ( 'message' in err && String ( ( err as any ) . message ) . includes ( 'FetchRequestCanceledException' ) ) )
113
+ ) ;
114
+ }
Original file line number Diff line number Diff line change
1
+ import { isAbortError } from '../internal/errors' ;
1
2
import { AnthropicError , APIUserAbortError } from '../error' ;
2
3
import {
3
4
type ContentBlock ,
@@ -289,7 +290,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
289
290
290
291
#handleError = ( error : unknown ) => {
291
292
this . #errored = true ;
292
- if ( error instanceof Error && error . name === 'AbortError' ) {
293
+ if ( isAbortError ( error ) ) {
293
294
error = new APIUserAbortError ( ) ;
294
295
}
295
296
if ( error instanceof APIUserAbortError ) {
You can’t perform that action at this time.
0 commit comments