Skip to content

Commit

Permalink
fix: return statusText with the response (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jan 30, 2019
1 parent 448f997 commit d2a0e85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface GaxiosResponse<T = any> {
config: GaxiosOptions;
data: T;
status: number;
statusText: string;
headers: Headers;
}

Expand Down
8 changes: 7 additions & 1 deletion src/gaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ export class Gaxios {
headers[key] = value;
});

return {config: opts, data: data as T, headers, status: res.status};
return {
config: opts,
data: data as T,
headers,
status: res.status,
statusText: res.statusText
};
}
}
9 changes: 9 additions & 0 deletions test/test.getch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ describe('🎏 data handling', () => {
scope.done();
assert.strictEqual(res.data, body);
});

it('should return status text', async () => {
const body = {hello: '🌎'};
const scope = nock(url).get('/').reply(200, body);
const res = await request({url});
scope.done();
assert.ok(res.data);
assert.strictEqual(res.statusText, 'OK');
});
});

describe('🍂 defaults & instances', () => {
Expand Down

0 comments on commit d2a0e85

Please sign in to comment.