From 0decb9d82c34f892a4b9453096bc6b609b71819d Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Sat, 4 Jul 2020 17:49:02 +0200 Subject: [PATCH] return status code 200 on VIOLATION_STRICT_MODE_VOUTS --- pushtx/pushtx-rest-api.js | 17 +++++++++++++---- pushtx/transactions-scheduler.js | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pushtx/pushtx-rest-api.js b/pushtx/pushtx-rest-api.js index c17923a..b05dd5b 100644 --- a/pushtx/pushtx-rest-api.js +++ b/pushtx/pushtx-rest-api.js @@ -165,7 +165,7 @@ class PushTxRestApi { 'message': faults, 'code': errors.pushtx.VIOLATION_STRICT_MODE_VOUTS }) - }) + }, 200) } } } catch(e) { @@ -198,7 +198,13 @@ class PushTxRestApi { await this.scheduler.schedule(req.body.script) HttpServer.sendOk(res) } catch(e) { - this._traceError(res, e) + // Returns code 200 if VIOLATION_STRICT_MODE_VOUTS + if (e.message && e.message.code && e.message.code == errors.pushtx.VIOLATION_STRICT_MODE_VOUTS) { + e.message = JSON.stringify(e.message) + this._traceError(res, e, 200) + } else { + this._traceError(res, e) + } } } @@ -206,10 +212,13 @@ class PushTxRestApi { * Trace an error during push * @param {object} res - http response object * @param {object} err - error object + * @param {int} errorCode - error code (optional) */ - _traceError(res, err) { + _traceError(res, err, errorCode) { let ret = null + errorCode = errorCode == null ? 400 : errorCode + try { if (err.message) { let msg = {} @@ -232,7 +241,7 @@ class PushTxRestApi { Logger.error(e, 'PushTx : ') ret = e } finally { - HttpServer.sendError(res, ret) + HttpServer.sendError(res, ret, errorCode) } } diff --git a/pushtx/transactions-scheduler.js b/pushtx/transactions-scheduler.js index 25edc68..11f085c 100644 --- a/pushtx/transactions-scheduler.js +++ b/pushtx/transactions-scheduler.js @@ -112,10 +112,10 @@ class TransactionsScheduler { // Return if strict_mode_vout has detected errors if (faults.length > 0) { throw { - 'message': JSON.stringify({ + 'message': { 'message': faults, 'code': errors.pushtx.VIOLATION_STRICT_MODE_VOUTS - }) + } } }