diff --git a/test/errors.js b/test/errors.js new file mode 100644 index 0000000..c73b286 --- /dev/null +++ b/test/errors.js @@ -0,0 +1,21 @@ +import test from 'ava' +import nock from 'nock' +import data from './fixtures/data' +import Onionoo from '../' + +test('Handle HTML responses for errors', async t => { + const onionoo = new Onionoo() + + const defaultEndpoint = data.defaultEndpoints[0] + const scope = nock(data.defaultBaseUrl) + .get(`/${defaultEndpoint}`) + .reply(400, data.dummy400Response) + + try { + await onionoo[defaultEndpoint]() + } catch (e) { + t.deepEqual(e.response.body, data.dummy400Response) + } + + t.truthy(scope.isDone()) +}) diff --git a/test/fixtures/data.js b/test/fixtures/data.js index 8b6eb37..37eceea 100644 --- a/test/fixtures/data.js +++ b/test/fixtures/data.js @@ -23,5 +23,6 @@ module.exports = { ], bridges_published: '2016-12-22 04:41:03', bridges: [] - } + }, + dummy400Response: '\n\n\nError 400 Bad Request\n\n

HTTP ERROR 400

\n

Problem accessing /summary. Reason:\n

    Bad Request


Powered by Jetty://
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n\n' }