Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bootstrap": "lerna bootstrap",
"clean": "lerna clean",
"lint": "lerna run lint --stream",
"postinstall": "npm run bootstrap",
"publish": "lerna publish",
"test": "lerna run test --stream",
"version": "conventional-changelog --pkg lerna.json -i CHANGELOG.md -s && git add CHANGELOG.md"
Expand Down
19 changes: 19 additions & 0 deletions packages/api/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ describe('#accessors', () => {
describe('#fetch', () => {
const petId = 123;

it('should reject for error-level status codes', () => {
expect.assertions(2);

const response = {
error: 'ENDPOINT_NOTFOUND',
message: `The endpoint you called (GET /pets/${petId}) doesn't exist`,
};

const mock = nock(petstoreServerUrl).delete(`/pets/${petId}`).reply(404, response);

return petstoreSdk.deletePet({ id: petId }).catch(async err => {
expect(err.status).toBe(404);

const json = await err.json();
expect(json).toStrictEqual(response);
mock.done();
});
});

it('should contain a custom user agent for the library in requests', () => {
expect.assertions(2);

Expand Down
8 changes: 7 additions & 1 deletion packages/api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ class Sdk {
function fetchOperation(spec, operation, body, metadata) {
const har = oasToHar(spec, operation, prepareParams(operation, body, metadata), prepareAuth(authKeys, operation));

return fetchHar(har, `${pkg.name} (node)/${pkg.version}`);
return fetchHar(har, `${pkg.name} (node)/${pkg.version}`).then(res => {
if (res.status >= 400 && res.status <= 599) {
throw res;
}

return res;
});
}

function loadMethods(spec) {
Expand Down