@@ -93,8 +93,6 @@ class FetchLoader implements Loader<LoaderContext> {
93
93
stats . loading . start = self . performance . now ( ) ;
94
94
95
95
const initParams = getRequestParameters ( context , this . controller . signal ) ;
96
- const onProgress : LoaderOnProgress < LoaderContext > | undefined =
97
- callbacks . onProgress ;
98
96
const isArrayBuffer = context . responseType === 'arraybuffer' ;
99
97
const LENGTH = isArrayBuffer ? 'byteLength' : 'length' ;
100
98
const { maxTimeToFirstByteMs, maxLoadTimeMs } = config . loadPolicy ;
@@ -109,8 +107,10 @@ class FetchLoader implements Loader<LoaderContext> {
109
107
? maxTimeToFirstByteMs
110
108
: maxLoadTimeMs ;
111
109
this . requestTimeout = self . setTimeout ( ( ) => {
112
- this . abortInternal ( ) ;
113
- callbacks . onTimeout ( stats , context , this . response ) ;
110
+ if ( this . callbacks ) {
111
+ this . abortInternal ( ) ;
112
+ this . callbacks . onTimeout ( stats , context , this . response ) ;
113
+ }
114
114
} , config . timeout ) ;
115
115
116
116
const fetchPromise = isPromise ( this . request )
@@ -127,8 +127,10 @@ class FetchLoader implements Loader<LoaderContext> {
127
127
config . timeout = maxLoadTimeMs ;
128
128
this . requestTimeout = self . setTimeout (
129
129
( ) => {
130
- this . abortInternal ( ) ;
131
- callbacks . onTimeout ( stats , context , this . response ) ;
130
+ if ( this . callbacks ) {
131
+ this . abortInternal ( ) ;
132
+ this . callbacks . onTimeout ( stats , context , this . response ) ;
133
+ }
132
134
} ,
133
135
maxLoadTimeMs - ( first - stats . loading . start ) ,
134
136
) ;
@@ -145,6 +147,7 @@ class FetchLoader implements Loader<LoaderContext> {
145
147
146
148
stats . total = getContentLength ( response . headers ) || stats . total ;
147
149
150
+ const onProgress = this . callbacks ?. onProgress ;
148
151
if ( onProgress && Number . isFinite ( config . highWaterMark ) ) {
149
152
return this . loadProgressively (
150
153
response ,
@@ -184,11 +187,12 @@ class FetchLoader implements Loader<LoaderContext> {
184
187
code : response . status ,
185
188
} ;
186
189
190
+ const onProgress = this . callbacks ?. onProgress ;
187
191
if ( onProgress && ! Number . isFinite ( config . highWaterMark ) ) {
188
192
onProgress ( stats , context , responseData , response ) ;
189
193
}
190
194
191
- callbacks . onSuccess ( loaderResponse , stats , context , response ) ;
195
+ this . callbacks ? .onSuccess ( loaderResponse , stats , context , response ) ;
192
196
} )
193
197
. catch ( ( error ) => {
194
198
self . clearTimeout ( this . requestTimeout ) ;
@@ -199,7 +203,7 @@ class FetchLoader implements Loader<LoaderContext> {
199
203
// when destroying, 'error' itself can be undefined
200
204
const code : number = ! error ? 0 : error . code || 0 ;
201
205
const text : string = ! error ? null : error . message ;
202
- callbacks . onError (
206
+ this . callbacks ? .onError (
203
207
{ code, text } ,
204
208
context ,
205
209
error ? error . details : null ,
0 commit comments