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 <rambat1010@gmail.com>
This commit is contained in:
Johnny Chen 2024-07-20 06:27:21 +08:00 committed by GitHub
parent 5df6b5f7d9
commit c4158b97d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();