From 641d6a41eb92ca8be989e003b90a83751592581b Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 25 May 2018 14:18:14 +0200 Subject: [PATCH] fix circular when serializing errors --- lib/open_id_connect_error.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/open_id_connect_error.js b/lib/open_id_connect_error.js index 96a55d9d..8f29db3b 100644 --- a/lib/open_id_connect_error.js +++ b/lib/open_id_connect_error.js @@ -1,16 +1,6 @@ /* eslint-disable camelcase */ -/* istanbul ignore next */ -function responseInspect() { - return { - body: this.body, - url: this.url, - statusCode: this.statusCode, - headers: this.headers, - }; -} - -module.exports = class OpenIdConnectError extends Error { +class OpenIdConnectError extends Error { constructor({ error_description, error, @@ -23,12 +13,24 @@ module.exports = class OpenIdConnectError extends Error { Object.assign( this, - { error, name: this.constructor.name }, + { error }, (error_description && { error_description }), (error_uri && { error_uri }), (state && { state }), - (scope && { scope }), - (response && (response.inspect = responseInspect) && { response }) + (scope && { scope }) ); + + Object.defineProperty(this, 'response', { + value: response, + }); } -}; +} + +Object.defineProperty(OpenIdConnectError.prototype, 'name', { + enumerable: false, + configurable: true, + value: 'OpenIdConnectError', + writable: true, +}); + +module.exports = OpenIdConnectError;