Skip to content

Commit c7e70ab

Browse files
refactor: remover try/catch suprimido pelo error handler
1 parent 31d99b8 commit c7e70ab

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/middlewares/authentication-middleware.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@ const constant = require('../utils/constants')
55
const usuariosService = require('../services/usuarios-service')
66

77
exports.checkAdm = async (req, res, next) => {
8-
try {
9-
if (!await tokenValido(req.headers)) {
10-
return res.status(401).send({ message: constant.TOKEN_INVALID })
11-
}
12-
const tokenDecodificado = authService.verifyToken(req.headers.authorization)
13-
if (!await usuariosService.usuarioEhAdministrador(tokenDecodificado)) {
14-
return res.status(403).send({ message: constant.NECESSARIO_ADM })
15-
}
16-
next()
17-
} catch (error) {
18-
/* istanbul ignore next */
19-
res.status(500).send({ message: constant.INTERNAL_ERROR, error })
8+
if (!await tokenValido(req.headers)) {
9+
return res.status(401).send({ message: constant.TOKEN_INVALID })
2010
}
11+
const tokenDecodificado = authService.verifyToken(req.headers.authorization)
12+
if (!await usuariosService.usuarioEhAdministrador(tokenDecodificado)) {
13+
return res.status(403).send({ message: constant.NECESSARIO_ADM })
14+
}
15+
next()
2116
}
2217

2318
exports.checkToken = async (req, res, next) => {
24-
try {
25-
if (!await tokenValido(req.headers)) {
26-
return res.status(401).send({ message: constant.TOKEN_INVALID })
27-
}
28-
next()
29-
} catch (error) {
30-
/* istanbul ignore next */
31-
res.status(500).send({ message: constant.INTERNAL_ERROR, error })
19+
if (!await tokenValido(req.headers)) {
20+
return res.status(401).send({ message: constant.TOKEN_INVALID })
3221
}
22+
next()
3323
}
3424

3525
async function tokenValido ({ authorization }) {

0 commit comments

Comments
 (0)