From c4158b97d67c9b423db2a33caf4a74c1e28841b0 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Sat, 20 Jul 2024 06:27:21 +0800 Subject: [PATCH] bugfix: API new user return 400 if user creation failed (#1898) * return 400 if user creation failed The client might not check the error field unless they realize it's a 4xx error instead of 200 success. * Update index.js * use one-liner style --------- Co-authored-by: Timothy Carambat --- server/endpoints/api/admin/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/endpoints/api/admin/index.js b/server/endpoints/api/admin/index.js index dd47f374..d60a0f26 100644 --- a/server/endpoints/api/admin/index.js +++ b/server/endpoints/api/admin/index.js @@ -133,7 +133,7 @@ function apiAdminEndpoints(app) { const newUserParams = reqBody(request); const { user: newUser, error } = await User.create(newUserParams); - response.status(200).json({ user: newUser, error }); + response.status(newUser ? 200 : 400).json({ user: newUser, error }); } catch (e) { console.error(e); response.sendStatus(500).end();