Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Error on "get_user" when user doesn't exists #53

Open
fabiothz opened this issue Jun 3, 2022 · 2 comments
Open

Error on "get_user" when user doesn't exists #53

fabiothz opened this issue Jun 3, 2022 · 2 comments
Labels
pull requests welcome An issue that we would like to see fixed, but don't have the time for to fix them personally

Comments

@fabiothz
Copy link

fabiothz commented Jun 3, 2022

Wen i try to search for a user that doesn't exist, an error occurs:

{
  "detail": "list index out of range"
}

Occurs in the line below, as the API returns a empty array.

return KeycloakUser(**response.json()[0])

A suggestion would be to check before instantiating the object:

response_json = response.json()
return KeycloakUser(**response_json[0]) if len(response_json) else None

This way the API will allow me to check if a user exists in keycloak.
What do you think?

@yannicschroeer
Copy link
Collaborator

Hey @fabiothz. Nice catch, this really shouldn't happen.

Personally, I would expect an error to be thrown here. Something like a UserNotFound exception. This would be the most explicit and customizable behavior I can think of. I would wait for @JonasScholl opinion on this

@yannicschroeer yannicschroeer added the pull requests welcome An issue that we would like to see fixed, but don't have the time for to fix them personally label Jun 3, 2022
stratosgear added a commit to stratosgear/fastapi-keycloak that referenced this issue Jul 16, 2022
JonasScholl pushed a commit that referenced this issue Jul 23, 2022
@stratosgear
Copy link
Contributor

I believe this can now be closed! @fabiothz Are you still experiencing the issue with the latest release?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pull requests welcome An issue that we would like to see fixed, but don't have the time for to fix them personally
Projects
None yet
Development

No branches or pull requests

3 participants