@@ -138,7 +138,7 @@ export abstract class HTTPDataSource<TContext = any> extends DataSource {
138138 *
139139 * @param request
140140 */
141- protected onRequest ?( request : Request ) : void
141+ protected async onRequest ?( request : Request ) : Promise < void >
142142
143143 /**
144144 * onResponse is executed when a response has been received.
@@ -229,19 +229,19 @@ export abstract class HTTPDataSource<TContext = any> extends DataSource {
229229 }
230230
231231 private async performRequest < TResult > (
232- options : Request ,
232+ request : Request ,
233233 cacheKey : string ,
234234 ) : Promise < Response < TResult > > {
235- this . onRequest ?.( options )
235+ await this . onRequest ?.( request )
236236
237237 try {
238238 const responseData = await this . pool . request ( {
239- method : options . method ,
240- origin : options . origin ,
241- path : options . path ,
242- body : options . body ,
243- headers : options . headers ,
244- signal : options . signal ,
239+ method : request . method ,
240+ origin : request . origin ,
241+ path : request . path ,
242+ body : request . body ,
243+ headers : request . headers ,
244+ signal : request . signal ,
245245 } )
246246
247247 responseData . body . setEncoding ( 'utf8' )
@@ -262,29 +262,29 @@ export abstract class HTTPDataSource<TContext = any> extends DataSource {
262262 body : json ,
263263 }
264264
265- this . onResponse < TResult > ( options , response )
265+ this . onResponse < TResult > ( request , response )
266266
267267 // let's see if we can fill the shared cache
268- if ( options . requestCache && this . isResponseCacheable < TResult > ( options , response ) ) {
269- response . maxTtl = Math . max ( options . requestCache . maxTtl , options . requestCache . maxTtlIfError )
268+ if ( request . requestCache && this . isResponseCacheable < TResult > ( request , response ) ) {
269+ response . maxTtl = Math . max ( request . requestCache . maxTtl , request . requestCache . maxTtlIfError )
270270 const cachedResponse = JSON . stringify ( response )
271271 this . cache
272272 . set ( cacheKey , cachedResponse , {
273- ttl : options . requestCache ?. maxTtl ,
273+ ttl : request . requestCache ?. maxTtl ,
274274 } )
275275 . catch ( ( err ) => this . logger ?. error ( err ) )
276276 this . cache
277277 . set ( `staleIfError:${ cacheKey } ` , cachedResponse , {
278- ttl : options . requestCache ?. maxTtlIfError ,
278+ ttl : request . requestCache ?. maxTtlIfError ,
279279 } )
280280 . catch ( ( err ) => this . logger ?. error ( err ) )
281281 }
282282
283283 return response
284284 } catch ( error ) {
285- this . onError ?.( error , options )
285+ this . onError ?.( error , request )
286286
287- if ( options . requestCache ) {
287+ if ( request . requestCache ) {
288288 const cacheItem = await this . cache . get ( `staleIfError:${ cacheKey } ` )
289289 if ( cacheItem ) {
290290 const response : Response < TResult > = sjson . parse ( cacheItem )
0 commit comments