Skip to content

Commit

Permalink
fix circular when serializing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed May 25, 2018
1 parent d246000 commit 641d6a4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/open_id_connect_error.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

0 comments on commit 641d6a4

Please sign in to comment.