From 764bf30c780ce4998856cc38b4c93640856006d0 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Thu, 26 Nov 2020 15:41:45 +0100 Subject: [PATCH] update IndyError to class based error Signed-off-by: Timo Glastra --- wrappers/nodejs/src/IndyError.js | 45 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/wrappers/nodejs/src/IndyError.js b/wrappers/nodejs/src/IndyError.js index 5430e6f943..ff38da6f67 100644 --- a/wrappers/nodejs/src/IndyError.js +++ b/wrappers/nodejs/src/IndyError.js @@ -1,4 +1,3 @@ -const util = require('util') const capi = require('./indyBinding') const errors = { @@ -61,29 +60,31 @@ const errors = { 706: 'TransactionNotAllowedError' } -function IndyError (err) { - Error.call(this) - Error.captureStackTrace(this, this.constructor) - this.name = this.constructor.name - if (Object.prototype.hasOwnProperty.call(errors, err)) { - this.message = errors[err] - this.indyCode = err - this.indyName = errors[err] - try { - this.indyCurrentErrorJson = capi.getCurrentError() - const details = JSON.parse(this.indyCurrentErrorJson) - if (typeof details.message === 'string') { - this.indyMessage = details.message - } - if (typeof details.backtrace === 'string') { - this.indyBacktrace = details.backtrace - } - } catch (e) { +class IndyError extends Error { + constructor (err) { + super() + + this.name = this.constructor.name + Error.captureStackTrace(this, IndyError) + + if (Object.prototype.hasOwnProperty.call(errors, err)) { + this.message = errors[err] + this.indyCode = err + this.indyName = errors[err] + try { + this.indyCurrentErrorJson = capi.getCurrentError() + const details = JSON.parse(this.indyCurrentErrorJson) + if (typeof details.message === 'string') { + this.indyMessage = details.message + } + if (typeof details.backtrace === 'string') { + this.indyBacktrace = details.backtrace + } + } catch (e) {} + } else { + this.message = err + '' } - } else { - this.message = (err + '') } } -util.inherits(IndyError, Error) module.exports = IndyError