From 4f90bbd931a5f3589eff1984d9ad5129eb41b79a Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Tue, 17 Nov 2015 17:33:36 -0800 Subject: [PATCH] Add resultCode and resultMessage to submit failure RippledError --- src/common/errors.js | 3 ++- src/transaction/submit.js | 11 +++++------ test/api-test.js | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/errors.js b/src/common/errors.js index a748d656..daf7358f 100644 --- a/src/common/errors.js +++ b/src/common/errors.js @@ -2,10 +2,11 @@ const util = require('util'); class RippleError extends Error { - constructor(message) { + constructor(message, data) { super(message); this.name = this.constructor.name; this.message = message; + this.data = data; Error.captureStackTrace(this, this.constructor.name); } diff --git a/src/transaction/submit.js b/src/transaction/submit.js index ffdcc614..21cd7a45 100644 --- a/src/transaction/submit.js +++ b/src/transaction/submit.js @@ -24,15 +24,14 @@ function isImmediateRejection(engineResult: string): boolean { } function formatResponse(response) { - if (isImmediateRejection(response.engine_result)) { - const error = new utils.common.errors.RippledError('Submit failed'); - error.data = response; - throw error; - } - return { + const data = { resultCode: response.engine_result, resultMessage: response.engine_result_message }; + if (isImmediateRejection(response.engine_result)) { + throw new utils.common.errors.RippledError('Submit failed', data); + } + return data; } function submit(signedTransaction: string): Promise { diff --git a/test/api-test.js b/test/api-test.js index 9c87d383..f4399a07 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -205,6 +205,7 @@ describe('RippleAPI', function() { assert(false, 'Should throw RippledError'); }).catch(error => { assert(error instanceof this.api.errors.RippledError); + assert.strictEqual(error.data.resultCode, 'temBAD_FEE'); }); });