Skip to content

Commit

Permalink
update IndyError to class based error
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed May 17, 2021
1 parent 2cd9cf3 commit 764bf30
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions wrappers/nodejs/src/IndyError.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const util = require('util')
const capi = require('./indyBinding')

const errors = {
Expand Down Expand Up @@ -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

0 comments on commit 764bf30

Please sign in to comment.