Merge pull request #1163 from ubavic/unpair-logging

feat: add logging to middlewares
This commit is contained in:
Rafael Taranto 2022-03-18 23:52:20 +00:00 committed by GitHub
commit 5717dcbb58
2 changed files with 12 additions and 6 deletions

View file

@ -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

View file

@ -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)
return res.status(403).json({ error: 'forbidden' })
})
} }
module.exports = ca module.exports = ca