File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,6 +71,28 @@ describe('Basic Streaming Helper', () => {
7171 expect ( aborted ) . toBeTruthy ( )
7272 } )
7373
74+ it ( 'Check stream Response if pipe is aborted by abort signal' , async ( ) => {
75+ const ac = new AbortController ( )
76+ const req = new Request ( 'http://localhost/' , { signal : ac . signal } )
77+ const c = new Context ( req )
78+
79+ let aborted = false
80+ const res = stream ( c , async ( stream ) => {
81+ stream . onAbort ( ( ) => {
82+ aborted = true
83+ } )
84+ await stream . pipe ( new ReadableStream ( ) )
85+ } )
86+ if ( ! res . body ) {
87+ throw new Error ( 'Body is null' )
88+ }
89+ const reader = res . body . getReader ( )
90+ const pReading = reader . read ( )
91+ ac . abort ( )
92+ await pReading
93+ expect ( aborted ) . toBeTruthy ( )
94+ } )
95+
7496 it ( 'Check stream Response if error occurred' , async ( ) => {
7597 const onError = vi . fn ( )
7698 const res = stream (
Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ export const stream = (
2222 try {
2323 await cb ( stream )
2424 } catch ( e ) {
25- if ( e instanceof Error && onError ) {
25+ if ( e === undefined ) {
26+ // If reading is canceled without a reason value (e.g. by StreamingApi)
27+ // then the .pipeTo() promise will reject with undefined.
28+ // In this case, do nothing because the stream is already closed.
29+ } else if ( e instanceof Error && onError ) {
2630 await onError ( e , stream )
2731 } else {
2832 console . error ( e )
You can’t perform that action at this time.
0 commit comments