feat: tokenController pass errors

This commit is contained in:
Bobby Wibowo 2022-07-10 14:17:59 +07:00
parent 3a415165b4
commit 0f47ed76b0
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -1,7 +1,6 @@
const randomstring = require('randomstring') const randomstring = require('randomstring')
const perms = require('./permissionController') const perms = require('./permissionController')
const utils = require('./utilsController') const utils = require('./utilsController')
const apiErrorsHandler = require('./handlers/apiErrorsHandler')
const ClientError = require('./utils/ClientError') const ClientError = require('./utils/ClientError')
const ServerError = require('./utils/ServerError') const ServerError = require('./utils/ServerError')
@ -34,8 +33,8 @@ self.generateUniqueToken = async () => {
return null return null
} }
self.verify = async (req, res, next) => { self.verify = (req, res, next) => {
try { Promise.resolve().then(async () => {
const token = typeof req.body.token === 'string' const token = typeof req.body.token === 'string'
? req.body.token.trim() ? req.body.token.trim()
: '' : ''
@ -71,22 +70,18 @@ self.verify = async (req, res, next) => {
} }
await res.json(obj) await res.json(obj)
} catch (error) { }).catch(next)
return apiErrorsHandler(error, req, res, next)
}
} }
self.list = async (req, res, next) => { self.list = (req, res, next) => {
try { Promise.resolve().then(async () => {
const user = await utils.authorize(req) const user = await utils.authorize(req)
await res.json({ success: true, token: user.token }) await res.json({ success: true, token: user.token })
} catch (error) { }).catch(next)
return apiErrorsHandler(error, req, res, next)
}
} }
self.change = async (req, res, next) => { self.change = (req, res, next) => {
try { Promise.resolve().then(async () => {
const user = await utils.authorize(req, 'token') const user = await utils.authorize(req, 'token')
const newToken = await self.generateUniqueToken() const newToken = await self.generateUniqueToken()
@ -103,9 +98,7 @@ self.change = async (req, res, next) => {
self.onHold.delete(newToken) self.onHold.delete(newToken)
await res.json({ success: true, token: newToken }) await res.json({ success: true, token: newToken })
} catch (error) { }).catch(next)
return apiErrorsHandler(error, req, res, next)
}
} }
module.exports = self module.exports = self