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.
This commit is contained in:
Rafael Taranto 2018-09-11 08:57:59 -03:00 committed by Josh Harvey
parent 46d73fadf9
commit f43149dca7

View file

@ -25,6 +25,7 @@ const argv = require('minimist')(process.argv.slice(2))
const CLOCK_SKEW = 60 * 1000 const CLOCK_SKEW = 60 * 1000
const REQUEST_TTL = 3 * 60 * 1000 const REQUEST_TTL = 3 * 60 * 1000
const SERIALIZATION_FAILURE_CODE = '40001'
const pids = {} const pids = {}
const reboots = {} const reboots = {}
@ -134,6 +135,7 @@ function postTx (req, res, next) {
return res.json(tx) return res.json(tx)
}) })
.catch(err => { .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.StaleTxError) return res.status(409).json({})
if (err instanceof E.RatchetError) return res.status(409).json({}) if (err instanceof E.RatchetError) return res.status(409).json({})