diff --git a/lib/helpers/is_standard_body_error.js b/lib/helpers/is_standard_body_error.js index 77c0a1ed..870148f4 100644 --- a/lib/helpers/is_standard_body_error.js +++ b/lib/helpers/is_standard_body_error.js @@ -2,7 +2,7 @@ module.exports = function isStandardBodyError(error) { if (error instanceof this.httpClient.HTTPError) { try { error.response.body = JSON.parse(error.response.body); - return !!error.response.body.error; + return typeof error.response.body.error === 'string' && error.response.body.error.length; } catch (err) {} } diff --git a/test/issuer/discover_issuer.test.js b/test/issuer/discover_issuer.test.js index ab01564f..c8d4c501 100644 --- a/test/issuer/discover_issuer.test.js +++ b/test/issuer/discover_issuer.test.js @@ -204,6 +204,20 @@ const fail = () => { throw new Error('expected promise to be rejected'); }; }); }); + it('is rejected with HTTPError when error is not a string', function () { + nock('https://op.example.com', { allowUnmocked: true }) + .get('/.well-known/openid-configuration') + .reply(400, { + error: {}, + error_description: 'bad things are happening', + }); + + return Issuer.discover('https://op.example.com') + .then(fail, function (error) { + expect(error).to.be.an.instanceof(Issuer.httpClient.HTTPError); + }); + }); + it('is rejected with when non 200 is returned', function () { nock('https://op.example.com', { allowUnmocked: true }) .get('/.well-known/openid-configuration')