Skip to content

Commit

Permalink
feat: populate GaxiosResponse with raw response information (res.url) (
Browse files Browse the repository at this point in the history
  • Loading branch information
marapper authored and bcoe committed Nov 25, 2019
1 parent ba9777b commit 53a7f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export interface Headers {
}
export type GaxiosPromise<T = any> = Promise<GaxiosResponse<T>>;

export interface GaxiosXMLHttpRequest {
responseURL: string;
}

export interface GaxiosResponse<T = any> {
config: GaxiosOptions;
data: T;
status: number;
statusText: string;
headers: Headers;
request: GaxiosXMLHttpRequest;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/gaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ export class Gaxios {
headers,
status: res.status,
statusText: res.statusText,

// XMLHttpRequestLike
request: {
responseURL: res.url,
},
};
}
}
4 changes: 4 additions & 0 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('🥁 configuration options', () => {
const res = await request({url});
scopes.forEach(x => x.done());
assert.deepStrictEqual(res.data, body);
assert.strictEqual(res.request.responseURL, `${url}/foo`);
});

it('should support disabling redirects', async () => {
Expand All @@ -139,6 +140,9 @@ describe('🥁 configuration options', () => {
status: 200,
statusText: 'OK',
headers: {},
request: {
responseURL: url,
},
};
const adapter = (options: GaxiosOptions) => {
return Promise.resolve(response);
Expand Down

0 comments on commit 53a7f54

Please sign in to comment.