mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
Add resultCode and resultMessage to submit failure RippledError
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user