Skip to content

Commit

Permalink
feat: add XMLHttpRequest-like request in response object
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Bondar authored and Sergey Bondar committed Nov 15, 2019
1 parent 8dd1324 commit 836fca1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ export interface Headers {
}
export type GaxiosPromise<T = any> = Promise<GaxiosResponse<T>>;

export interface GaxiosXMLHttpRequest {
responseURL: string;
status: number;
statusText: string;
}

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

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

// XMLHttpRequestLike
request: {
responseURL: res.url,
status: res.status,
statusText: res.statusText,
},
};
}
}
5 changes: 5 additions & 0 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ describe('🥁 configuration options', () => {
status: 200,
statusText: 'OK',
headers: {},
request: {
responseURL: url,
status: 200,
statusText: 'OK',
},
};
const adapter = (options: GaxiosOptions) => {
return Promise.resolve(response);
Expand Down

0 comments on commit 836fca1

Please sign in to comment.