Skip to content

Commit

Permalink
Pass dispatcher options to global fetch (#653)
Browse files Browse the repository at this point in the history
* Pass dispatcher options to global fetch

* Pass down all args to base fetch
  • Loading branch information
Kruspe authored Jul 1, 2024
1 parent 740000d commit b39b5e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk_contrib/fetch/lib/fetch_p.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const enableCapture = function enableCapture(baseFetchFunction, requestClass, do
const requestClone = request.clone();
let response;
try {
response = await baseFetchFunction(requestClone);
response = await baseFetchFunction(...args);

if (thisSubsegmentCallback) {
thisSubsegmentCallback(subsegment, requestClone, response);
Expand Down
11 changes: 11 additions & 0 deletions sdk_contrib/fetch/test/unit/fetch_p.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ describe('Unit tests', function () {
response.should.equal(stubValidResponse);
});

it('resolves to response through proxy when fetch options are supplied', async function() {
const activeFetch = captureFetch(true);
const proxyStub = sinon.stub();
const request = new FetchRequest('https://www.foo.com/test');
const response = await activeFetch(request, {
dispatcher: proxyStub
});
stubFetch.should.have.been.calledOnceWith(request, {dispatcher: proxyStub});
response.should.equal(stubValidResponse);
});

it('calls subsegmentCallback with error upon fetch throwing', async function () {
const spyCallback = sandbox.spy();
const activeFetch = captureFetch(true, spyCallback);
Expand Down

0 comments on commit b39b5e2

Please sign in to comment.