Explorar el Código

Send 401 rather than 400 error for invalid token

sbkwgh hace 8 años
padre
commit
0bf11850f5
Se han modificado 1 ficheros con 6 adiciones y 3 borrados
  1. 6 3
      routes/user.js

+ 6 - 3
routes/user.js

@@ -53,7 +53,6 @@ router.post('/', async (req, res) => {
 			}})
 
 			if(adminUser) {
-
 				validationErrors.push(Errors.missingParameter('token'))
 				throw Errors.VALIDATION_ERROR
 			} else {
@@ -68,8 +67,7 @@ router.post('/', async (req, res) => {
 			if(token && token.isValid()) {
 				userParams.admin = true
 			} else {
-				validationErrors.push(Errors.invalidToken)
-				throw Errors.VALIDATION_ERROR
+				throw Errors.invalidToken
 			}
 		}
 
@@ -97,6 +95,11 @@ router.post('/', async (req, res) => {
 			res.json({
 				errors: [Errors.accountAlreadyCreated]
 			})
+		} else if (err = Errors.invalidToken) {
+			res.status(401)
+			res.json({
+				errors: [Errors.invalidToken]
+			})
 		} else {
 			res.status(500)
 			res.json({