浏览代码

Throw accoutn does not exist error if account does not exist

sbkwgh 8 年之前
父节点
当前提交
b3839bc591
共有 1 个文件被更改,包括 11 次插入4 次删除
  1. 11 4
      routes/user.js

+ 11 - 4
routes/user.js

@@ -124,12 +124,19 @@ router.get('/:username', async (req, res) => {
 			where: { username: req.params.username }
 		})
 
+		if(!user) throw Errors.accountDoesNotExist
+
 		res.json(user.toJSON())
 	} catch (err) {
-		res.status(500)
-		res.json({
-			errors: [Errors.unknown]
-		})
+		if(err === Errors.accountDoesNotExist) {
+			res.status(400)
+			res.json({ errors: [err] })
+		} else {
+			res.status(500)
+			res.json({
+				errors: [Errors.unknown]
+			})
+		}
 	}
 })