Improve transaction errors (#194)
* Improve transaction errors * Fix standard styling errors
This commit is contained in:
parent
3cffbedd9a
commit
b47af59a7f
1 changed files with 25 additions and 25 deletions
|
|
@ -46,7 +46,7 @@ function poll (req, res, next) {
|
|||
const pi = plugins(settings, deviceId)
|
||||
const hasLightning = checkHasLightning(settings)
|
||||
|
||||
pids[deviceId] = {pid, ts: Date.now()}
|
||||
pids[deviceId] = { pid, ts: Date.now() }
|
||||
|
||||
return pi.pollQueries(serialNumber, deviceTime, req.query)
|
||||
.then(results => {
|
||||
|
|
@ -141,8 +141,8 @@ function postTx (req, res, next) {
|
|||
logger.warn('Harmless DB conflict, the query will be retried.')
|
||||
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({})
|
||||
if (err instanceof E.StaleTxError) return res.status(409).json({ errorType: 'stale' })
|
||||
if (err instanceof E.RatchetError) return res.status(409).json({ errorType: 'ratchet' })
|
||||
|
||||
throw err
|
||||
})
|
||||
|
|
@ -202,7 +202,7 @@ function getCustomerWithPhoneCode (req, res, next) {
|
|||
return pi.getPhoneCode(phone)
|
||||
.then(code => {
|
||||
return addOrUpdateCustomer(req)
|
||||
.then(customer => respond(req, res, {code, customer}))
|
||||
.then(customer => respond(req, res, { code, customer }))
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.name === 'BadNumberError') throw httpError('Bad number', 401)
|
||||
|
|
@ -226,7 +226,7 @@ function updateCustomer (req, res, next) {
|
|||
.then(newPatch => customers.updatePhotoCard(id, newPatch))
|
||||
.then(newPatch => customers.update(id, newPatch))
|
||||
})
|
||||
.then(customer => respond(req, res, {customer}))
|
||||
.then(customer => respond(req, res, { customer }))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ function getLastSeen (req, res, next) {
|
|||
|
||||
function updateLogs (req, res, next) {
|
||||
return logs.update(req.deviceId, req.body.logs)
|
||||
.then(status => res.json({success: status}))
|
||||
.then(status => res.json({ success: status }))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
|
|
@ -246,8 +246,8 @@ function ca (req, res) {
|
|||
const token = req.query.token
|
||||
|
||||
return pairing.authorizeCaDownload(token)
|
||||
.then(ca => res.json({ca}))
|
||||
.catch(() => res.status(403).json({error: 'forbidden'}))
|
||||
.then(ca => res.json({ ca }))
|
||||
.catch(() => res.status(403).json({ error: 'forbidden' }))
|
||||
}
|
||||
|
||||
function pair (req, res, next) {
|
||||
|
|
@ -259,7 +259,7 @@ function pair (req, res, next) {
|
|||
.then(valid => {
|
||||
if (valid) {
|
||||
return helpers.updateMachineDefaults(deviceId)
|
||||
.then(() => res.json({status: 'paired'}))
|
||||
.then(() => res.json({ status: 'paired' }))
|
||||
}
|
||||
|
||||
throw httpError('Pairing failed')
|
||||
|
|
@ -272,7 +272,7 @@ function errorHandler (err, req, res, next) {
|
|||
? err.code || 500
|
||||
: 500
|
||||
|
||||
const json = {error: err.message}
|
||||
const json = { error: err.message }
|
||||
|
||||
if (statusCode >= 400) logger.error(err)
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ function filterOldRequests (req, res, next) {
|
|||
req.deviceName, (delta / 1000).toFixed(2))
|
||||
}
|
||||
|
||||
if (delta > REQUEST_TTL) return res.status(408).json({error: 'stale'})
|
||||
if (delta > REQUEST_TTL) return res.status(408).json({ error: 'stale' })
|
||||
next()
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ function authorize (req, res, next) {
|
|||
return next()
|
||||
}
|
||||
|
||||
return res.status(403).json({error: 'Forbidden'})
|
||||
return res.status(403).json({ error: 'Forbidden' })
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
|
|
@ -337,9 +337,9 @@ const configRequiredRoutes = [
|
|||
const app = express()
|
||||
const localApp = express()
|
||||
|
||||
app.use(helmet({noCache: true}))
|
||||
app.use(bodyParser.json({limit: '2mb'}))
|
||||
app.use(morgan('dev', {skip, stream: logger.stream}))
|
||||
app.use(helmet({ noCache: true }))
|
||||
app.use(bodyParser.json({ limit: '2mb' }))
|
||||
app.use(morgan('dev', { skip, stream: logger.stream }))
|
||||
|
||||
// These two have their own authorization
|
||||
app.post('/pair', populateDeviceId, pair)
|
||||
|
|
@ -368,7 +368,7 @@ app.post('/logs', updateLogs)
|
|||
|
||||
app.use(errorHandler)
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({error: 'No such route'})
|
||||
res.status(404).json({ error: 'No such route' })
|
||||
})
|
||||
|
||||
localApp.get('/pid', (req, res) => {
|
||||
|
|
@ -440,7 +440,7 @@ function populateSettings (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
function createTerms(config) {
|
||||
function createTerms (config) {
|
||||
return {
|
||||
active: config.termsScreenActive,
|
||||
title: config.termsScreenTitle,
|
||||
|
|
@ -450,4 +450,4 @@ function createTerms(config) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = {app, localApp}
|
||||
module.exports = { app, localApp }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue