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 pairing = require('../pairing')
|
||||||
|
const logger = require('../logger')
|
||||||
|
|
||||||
const authorize = function (req, res, next) {
|
const authorize = function (req, res, next) {
|
||||||
const deviceId = req.deviceId
|
return pairing.isPaired(req.deviceId)
|
||||||
|
|
||||||
return pairing.isPaired(deviceId)
|
|
||||||
.then(deviceName => {
|
.then(deviceName => {
|
||||||
if (deviceName) {
|
if (deviceName) {
|
||||||
req.deviceId = deviceId
|
|
||||||
req.deviceName = deviceName
|
req.deviceName = deviceName
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.error(`Device ${req.deviceId} not found`)
|
||||||
return res.status(403).json({ error: 'Forbidden' })
|
return res.status(403).json({ error: 'Forbidden' })
|
||||||
})
|
})
|
||||||
.catch(next)
|
.catch(error => {
|
||||||
|
logger.error(error)
|
||||||
|
return next()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = authorize
|
module.exports = authorize
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
const pairing = require('../pairing')
|
const pairing = require('../pairing')
|
||||||
|
const logger = require('../logger')
|
||||||
|
|
||||||
function ca (req, res) {
|
function ca (req, res) {
|
||||||
const token = req.query.token
|
const token = req.query.token
|
||||||
|
|
||||||
return pairing.authorizeCaDownload(token)
|
return pairing.authorizeCaDownload(token)
|
||||||
.then(ca => res.json({ ca }))
|
.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
|
module.exports = ca
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue