Coverage for app/ddd/domain/error/user_error.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-15 01:44 +0000

1 

2from fastapi import status 

3 

4from app.core.base import BaseError 

5 

6# status.HTTP_400_BAD_REQUEST 

7# status.HTTP_409_CONFLICT 

8from app.ddd.domain import ErrorCode 

9 

10# Enumでエラー情報を定義 

11# class ErrorEnum(Enum): 

12# INVALID_INPUT = (4001, status.HTTP_404_NOT_FOUND, "Invalid input provided") 

13# USER_NOT_FOUND = (1404, status.HTTP_404_NOT_FOUND, "User with ID {user_id} was not found.") 

14# SERVER_ERROR = (5000, status.HTTP_404_NOT_FOUND, "Internal server error") 

15 

16class UserNotFoundError(BaseError): 

17 def __init__(self, user_id: str) -> None: 

18 message = "User with ID '{user_id}' was not found." 

19 super().__init__( 

20 error_code=ErrorCode.NOT_FOUND.str_value, 

21 status_code=status.HTTP_404_NOT_FOUND, 

22 description=message, 

23 # user_id=user_id, 

24 parameters={"user_id": user_id} # 修正 

25 ) 

26 

27class UserDuplicationError(BaseError): 

28 def __init__(self, user_id: str) -> None: 

29 message = "User with ID '{user_id}' already exists." 

30 super().__init__( 

31 error_code=ErrorCode.CONFLICT.str_value, 

32 status_code=status.HTTP_409_CONFLICT, 

33 description=message, 

34 # user_id=user_id, 

35 parameters={ 

36 "user_id": user_id, 

37 "hoge": "huga", 

38 } # 修正 

39 ) 

40 

41class UserUpdateConflictError(BaseError): 

42 def __init__(self, user_id: str) -> None: 

43 message = "User with ID '{user_id}' update conlict." 

44 super().__init__( 

45 error_code=ErrorCode.CONFLICT.str_value, 

46 status_code=status.HTTP_409_CONFLICT, 

47 description=message, 

48 # user_id=user_id, 

49 parameters={"user_id": user_id} # 修正 

50 ) 

51 

52 

53# class UserReportDuplicationError(BaseError): 

54# def __init__(self, user_report_id: str) -> None: 

55# message = "User Report with ID '{user_report_id}' already exists." 

56# super().__init__( 

57# error_code=ErrorCode.CONFLICT.str_value, 

58# status_code=status.HTTP_409_CONFLICT, 

59# description=message, 

60# user_report_id=user_report_id, 

61# ) 

62 

63 

64class UserAuthError(BaseError): 

65 def __init__(self) -> None: 

66 message = "auth error." 

67 super().__init__( 

68 error_code=ErrorCode.UNAUTHORIZED.str_value, 

69 status_code=status.HTTP_401_UNAUTHORIZED, 

70 description=message, 

71 # user_id=user_id, 

72 # parameters={"user_id": user_id} # 修正 

73 )