feat: add logging
chore: simplify code
This commit is contained in:
parent
6985c632cd
commit
547beac19f
2 changed files with 12 additions and 6 deletions
|
|
@ -1,19 +1,21 @@
|
|||
const pairing = require('../pairing')
|
||||
const logger = require('../logger')
|
||||
|
||||
const authorize = function (req, res, next) {
|
||||
const deviceId = req.deviceId
|
||||
|
||||
return pairing.isPaired(deviceId)
|
||||
return pairing.isPaired(req.deviceId)
|
||||
.then(deviceName => {
|
||||
if (deviceName) {
|
||||
req.deviceId = deviceId
|
||||
req.deviceName = deviceName
|
||||
return next()
|
||||
}
|
||||
|
||||
logger.error(`Device ${req.deviceId} not found`)
|
||||
return res.status(403).json({ error: 'Forbidden' })
|
||||
})
|
||||
.catch(next)
|
||||
.catch(error => {
|
||||
logger.error(error)
|
||||
return next()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = authorize
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
const pairing = require('../pairing')
|
||||
const logger = require('../logger')
|
||||
|
||||
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' }))
|
||||
.catch(error => {
|
||||
logger.error(error.message)
|
||||
res.status(403).json({ error: 'forbidden' })
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = ca
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue