Skip to content

Commit 782d464

Browse files
committed
fix: non-string error responses are not treated as OpenIdConnectError
``` { error: { code: 400, message: 'Request contains an invalid argument.', status: 'INVALID_ARGUMENT' } } ``` This is not an OpenIdConnectError and will no longer be returned as such, this will now fall under throwing HTTPError instances instead. See #125
1 parent 4ced646 commit 782d464

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/helpers/is_standard_body_error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = function isStandardBodyError(error) {
22
if (error instanceof this.httpClient.HTTPError) {
33
try {
44
error.response.body = JSON.parse(error.response.body);
5-
return !!error.response.body.error;
5+
return typeof error.response.body.error === 'string' && error.response.body.error.length;
66
} catch (err) {}
77
}
88

test/issuer/discover_issuer.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ const fail = () => { throw new Error('expected promise to be rejected'); };
204204
});
205205
});
206206

207+
it('is rejected with HTTPError when error is not a string', function () {
208+
nock('https://op.example.com', { allowUnmocked: true })
209+
.get('/.well-known/openid-configuration')
210+
.reply(400, {
211+
error: {},
212+
error_description: 'bad things are happening',
213+
});
214+
215+
return Issuer.discover('https://op.example.com')
216+
.then(fail, function (error) {
217+
expect(error).to.be.an.instanceof(Issuer.httpClient.HTTPError);
218+
});
219+
});
220+
207221
it('is rejected with when non 200 is returned', function () {
208222
nock('https://op.example.com', { allowUnmocked: true })
209223
.get('/.well-known/openid-configuration')

0 commit comments

Comments
 (0)