File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -229,8 +229,8 @@ class Api {
229229 this . resetRequest ( )
230230 }
231231
232- const { json, httpStatus } = result
233- return fn ? fn ( json , httpStatus ) : json
232+ const { json, httpStatus, response } = result
233+ return fn ? fn ( json , httpStatus , response ) : json
234234 }
235235
236236 /**
@@ -277,7 +277,7 @@ class Api {
277277 }
278278 }
279279
280- return { httpStatus : r . status , json }
280+ return { httpStatus : r . status , json, response : r }
281281 }
282282
283283 let content = ''
Original file line number Diff line number Diff line change @@ -281,6 +281,26 @@ describe('util/api', () => {
281281 expect ( code ) . to . equal ( httpStatusCode )
282282 } )
283283
284+ it ( 'passes the whole response as third parameter' , async ( ) => {
285+
286+ const stubbedResponse = {
287+ status : 202 ,
288+ json : stub ( ) . resolves ( { foo : 'bar' } ) ,
289+ statusText : 'Accepted' ,
290+ headers : new Map ( [ [ 'john' , 'doe' ] ] )
291+ }
292+ clientStub . resolves ( stubbedResponse )
293+
294+ const response = await api
295+ . context ( { fetch : clientStub } )
296+ . endpoint ( 'some/url' )
297+ . get ( ( json , statusCode , response ) => {
298+ return response
299+ } )
300+
301+ expect ( response . headers ) . to . equal ( stubbedResponse . headers )
302+ } )
303+
284304 it ( 'parses 3xx as successful' , async ( ) => {
285305 const httpStatusCode = 304
286306
@@ -598,7 +618,7 @@ describe('util/api', () => {
598618 } )
599619
600620 it ( 'has cleared method' , ( ) => {
601- expect ( api . config . method ) . to . equal ( 'get ' )
621+ expect ( api . config . method ) . to . equal ( 'GET ' )
602622 } )
603623
604624 it ( 'has not cleared client' , ( ) => {
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ export type ErrorHandlers = {
8282/**
8383 * Function to transform API response
8484 */
85- export type ResponseTransformer < T = any > = ( json : any , httpStatus : number ) => T ;
85+ export type ResponseTransformer < T = any > = ( json : any , httpStatus : number , response : Response ) => T ;
8686
8787/**
8888 * Fetch client interface
@@ -110,4 +110,5 @@ export type Response = {
110110export type QueryResult = {
111111 httpStatus : number ;
112112 json ?: any ;
113+ response : Response ;
113114} ;
You can’t perform that action at this time.
0 commit comments