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

View file

@ -10,6 +10,10 @@ from selfprivacy_api.graphql.common_types.user import (
get_users, get_users,
) )
from selfprivacy_api.graphql import IsAuthenticated from selfprivacy_api.graphql import IsAuthenticated
from selfprivacy_api.repositories.users.exceptions_kanidm import (
KanidmReturnUnknownResponseType,
KanidmReturnEmptyResponse,
)
@strawberry.type @strawberry.type
@ -17,7 +21,10 @@ class Users:
@strawberry.field(permission_classes=[IsAuthenticated]) @strawberry.field(permission_classes=[IsAuthenticated])
def get_user(self, username: str) -> typing.Optional[User]: def get_user(self, username: str) -> typing.Optional[User]:
"""Get users""" """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( all_users: typing.List[User] = strawberry.field(
permission_classes=[IsAuthenticated], resolver=get_users permission_classes=[IsAuthenticated], resolver=get_users