feat: add more errors processing

This commit is contained in:
dettlaff 2024-12-11 06:00:14 +04:00
parent cf3e6fe39e
commit 0700e2285f
2 changed files with 13 additions and 2 deletions

View file

@ -41,6 +41,7 @@ from selfprivacy_api.repositories.users.exceptions import (
)
from selfprivacy_api.repositories.users.exceptions_kanidm import (
KanidmDidNotReturnAdminPassword,
KanidmQueryError,
KanidmReturnEmptyResponse,
KanidmReturnUnknownResponseType,
)
@ -102,6 +103,7 @@ class UsersMutations:
KanidmDidNotReturnAdminPassword,
KanidmReturnUnknownResponseType,
KanidmReturnEmptyResponse,
KanidmQueryError,
) as error:
return return_failed_mutation_return(
message=error.get_error_message(),
@ -148,7 +150,7 @@ class UsersMutations:
code=400,
message=error.get_error_message(),
)
except KanidmDidNotReturnAdminPassword as error:
except (KanidmDidNotReturnAdminPassword, KanidmQueryError) as error:
return GenericMutationReturn(
success=False,
code=500,
@ -177,6 +179,7 @@ class UsersMutations:
KanidmDidNotReturnAdminPassword,
KanidmReturnUnknownResponseType,
KanidmReturnEmptyResponse,
KanidmQueryError,
) as error:
return return_failed_mutation_return(
message=error.get_error_message(),
@ -268,6 +271,7 @@ class UsersMutations:
RootIsNotAvailableForModification,
KanidmReturnUnknownResponseType,
KanidmReturnEmptyResponse,
KanidmQueryError,
) as error:
return PasswordResetLinkReturn(
success=False,

View file

@ -10,6 +10,10 @@ from selfprivacy_api.graphql.common_types.user import (
get_users,
)
from selfprivacy_api.graphql import IsAuthenticated
from selfprivacy_api.repositories.users.exceptions_kanidm import (
KanidmReturnUnknownResponseType,
KanidmReturnEmptyResponse,
)
@strawberry.type
@ -17,7 +21,10 @@ class Users:
@strawberry.field(permission_classes=[IsAuthenticated])
def get_user(self, username: str) -> typing.Optional[User]:
"""Get users"""
try:
return get_user_by_username(username)
except (KanidmReturnUnknownResponseType, KanidmReturnEmptyResponse):
pass # TODO what todo ??
all_users: typing.List[User] = strawberry.field(
permission_classes=[IsAuthenticated], resolver=get_users