From f43149dca7e6df2678ec6488cb650178f13772d5 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 11 Sep 2018 08:57:59 -0300 Subject: [PATCH] Improve serialization error handling on cash_out (#163) Made API calls return 204 on serialization error. When network is unreliable there is a high chance of generating a serialization exception. By returnig 204 on them the lamassu-machine can just continue working as if nothing happened. --- lib/routes.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/routes.js b/lib/routes.js index 074de437..d71fe074 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -25,6 +25,7 @@ const argv = require('minimist')(process.argv.slice(2)) const CLOCK_SKEW = 60 * 1000 const REQUEST_TTL = 3 * 60 * 1000 +const SERIALIZATION_FAILURE_CODE = '40001' const pids = {} const reboots = {} @@ -134,6 +135,7 @@ function postTx (req, res, next) { return res.json(tx) }) .catch(err => { + if (err.code === SERIALIZATION_FAILURE_CODE) return res.status(204).json({}) if (err instanceof E.StaleTxError) return res.status(409).json({}) if (err instanceof E.RatchetError) return res.status(409).json({})