Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
throwing properly on non 2XX errors, allows options.successCodes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Jan 29, 2021
1 parent 37c457c commit 97a3903
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@openfn/language-http",
"version": "3.1.0",
"version": "3.1.1",
"description": "An HTTP request language package for use with Open Function",
"homepage": "https://docs.openfn.org",
"repository": {
Expand Down
33 changes: 17 additions & 16 deletions test/index.js
Expand Up @@ -176,7 +176,8 @@ describe('get()', () => {
});
});

testServer.get('/api/badEndpoint').times(2).reply(400);
testServer.get('/api/badAuth').times(2).reply(404);
testServer.get('/api/crashDummy').times(2).reply(500);
});

it('prepares nextState properly', () => {
Expand Down Expand Up @@ -400,28 +401,28 @@ describe('get()', () => {
};

const finalState = await execute(
get('https://www.example.com/api/badEndpoint', {
options: { successCodes: [400] },
get('https://www.example.com/api/badAuth', {
options: { successCodes: [404] },
})
)(state);

expect(finalState.response.status).to.eql(400);
expect(finalState.response.status).to.eql(404);
});
});

it('throws an error for a non-2XX response', async () => {
const state = {
configuration: {},
data: {},
};
it('throws an error for a non-2XX response', async () => {
const state = {
configuration: {},
data: {},
};

const error = await execute(get('https://www.example.com/api/badEndpoint'))(
state
).catch(error => {
return JSON.parse(error.message);
});
const error = await execute(get('https://www.example.com/api/crashDummy'))(
state
).catch(error => {
return JSON.parse(error.message);
});

expect(error.status).to.eql(400);
expect(error.status).to.eql(500);
});
});

describe('post', () => {
Expand Down

0 comments on commit 97a3903

Please sign in to comment.