From 0700e2285fe4faf334b0a282eae3435fbdab488a Mon Sep 17 00:00:00 2001 From: dettlaff Date: Wed, 11 Dec 2024 06:00:14 +0400 Subject: [PATCH] feat: add more errors processing --- selfprivacy_api/graphql/mutations/users_mutations.py | 6 +++++- selfprivacy_api/graphql/queries/users.py | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/graphql/mutations/users_mutations.py b/selfprivacy_api/graphql/mutations/users_mutations.py index 7d68b39..fd801d1 100644 --- a/selfprivacy_api/graphql/mutations/users_mutations.py +++ b/selfprivacy_api/graphql/mutations/users_mutations.py @@ -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, diff --git a/selfprivacy_api/graphql/queries/users.py b/selfprivacy_api/graphql/queries/users.py index 992ce01..e5bd301 100644 --- a/selfprivacy_api/graphql/queries/users.py +++ b/selfprivacy_api/graphql/queries/users.py @@ -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""" - return get_user_by_username(username) + 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