Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better HTTP error codes #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

machadoug
Copy link

It's better to use 401 for lack of permission and 409 if the user already exists
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409

@@ -127,7 +127,7 @@ def read_user_by_id(
return user
if not crud.user.is_superuser(current_user):
raise HTTPException(
status_code=400, detail="The user doesn't have enough privileges"
status_code=401, detail="The user doesn't have enough privileges"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a 403

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machadoug Can you change it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, it should be a 403

@menkotoglou
Copy link

Seems like a stale PR. Could that be closed now?

@codespearhead
Copy link

codespearhead commented May 10, 2024

This branch is way behind main and OP hasn't acted on the suggestions, but the problem still persists:

Should be status_code=409

if user:
raise HTTPException(
status_code=400,
detail="The user with this email already exists in the system.",
)

Should be status_code=409

if user:
raise HTTPException(
status_code=400,
detail="The user with this email already exists in the system",
)

Should be `status_code=403 (fixed in 541dd75)

if not current_user.is_superuser:
raise HTTPException(
status_code=403,
detail="The user doesn't have enough privileges",
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants