From d7bbb64034af56dcf35e0e1d54c0bfd9e48f6b4f Mon Sep 17 00:00:00 2001 From: dettlaff Date: Mon, 11 Nov 2024 04:51:42 +0400 Subject: [PATCH] feat: UserRepositoryError --- selfprivacy_api/graphql/common_types/user.py | 7 +++++++ .../repositories/users/kanidm_user_repository.py | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/graphql/common_types/user.py b/selfprivacy_api/graphql/common_types/user.py index 4e6bb63..69b81e2 100644 --- a/selfprivacy_api/graphql/common_types/user.py +++ b/selfprivacy_api/graphql/common_types/user.py @@ -13,6 +13,13 @@ from selfprivacy_api.graphql.mutations.mutation_interface import ( ) +@strawberry.type +class UserRepositoryError(Exception): + """Error occurred during repo query""" + + error: str + + @strawberry.enum class UserType(Enum): NORMAL = "NORMAL" diff --git a/selfprivacy_api/repositories/users/kanidm_user_repository.py b/selfprivacy_api/repositories/users/kanidm_user_repository.py index b26b2c1..4060320 100644 --- a/selfprivacy_api/repositories/users/kanidm_user_repository.py +++ b/selfprivacy_api/repositories/users/kanidm_user_repository.py @@ -2,6 +2,7 @@ from typing import Optional import requests +from selfprivacy_api.graphql.common_types.user import UserRepositoryError from selfprivacy_api.utils import get_domain from selfprivacy_api.models.user import UserDataUser from selfprivacy_api.repositories.users.abstract_user_repository import ( @@ -33,14 +34,16 @@ class KanidmUserRepository(AbstractUserRepository): ) if response.status_code != 200: - raise KanidmQueryError( + raise UserRepositoryError( error=f"Kanidm returned unexpected HTTP status code. Error: {response.text}." ) json = response.json() return json["data"] except Exception as error: - raise KanidmQueryError(error=f"Kanidm request failed! Error: {str(error)}") + raise UserRepositoryError( + error=f"Kanidm request failed! Error: {str(error)}" + ) @staticmethod def create_user(username: str, password: str):