Add resultCode and resultMessage to submit failure RippledError

This commit is contained in:
Chris Clark
2015-11-17 17:33:36 -08:00
parent f196304a56
commit 4f90bbd931
3 changed files with 8 additions and 7 deletions

View File

@@ -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);
}

View File

@@ -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<Submit> {

View File

@@ -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');
});
});