Jelajahi Sumber

Send 401 rather than 400 error for invalid token

sbkwgh 8 tahun lalu
induk
melakukan
0bf11850f5
1 mengubah file dengan 6 tambahan dan 3 penghapusan
  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({