File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -66,11 +66,6 @@ export class Ky {
66
66
throw error ;
67
67
}
68
68
69
- // Now that we know a retry is not needed, close the ReadableStream of the cloned request.
70
- if ( ! ky . request . bodyUsed ) {
71
- await ky . request . body ?. cancel ( ) ;
72
- }
73
-
74
69
// If `onDownloadProgress` is passed, it uses the stream API internally
75
70
if ( ky . _options . onDownloadProgress ) {
76
71
if ( typeof ky . _options . onDownloadProgress !== 'function' ) {
@@ -88,7 +83,13 @@ export class Ky {
88
83
} ;
89
84
90
85
const isRetriableMethod = ky . _options . retry . methods . includes ( ky . request . method . toLowerCase ( ) ) ;
91
- const result = ( isRetriableMethod ? ky . _retry ( function_ ) : function_ ( ) ) as ResponsePromise ;
86
+ const result = ( isRetriableMethod ? ky . _retry ( function_ ) : function_ ( ) )
87
+ . finally ( async ( ) => {
88
+ // Now that we know a retry is not needed, close the ReadableStream of the cloned request.
89
+ if ( ! ky . request . bodyUsed ) {
90
+ await ky . request . body ?. cancel ( ) ;
91
+ }
92
+ } ) as ResponsePromise ;
92
93
93
94
for ( const [ type , mimeType ] of Object . entries ( responseTypes ) as ObjectEntries < typeof responseTypes > ) {
94
95
result [ type ] = async ( ) => {
You can’t perform that action at this time.
0 commit comments