Coverage for src/chainalysis/util_functions/exceptions.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-20 16:53 -0400

1class DataSolutionsSDKException(Exception): 

2 """Base class for SDK exceptions.""" 

3 

4 def __init__( 

5 self, 

6 message=None, 

7 status_code=0, 

8 ): 

9 super().__init__(message) 

10 self.status_code = status_code 

11 

12 def get_exception(self): 

13 return self 

14 

15 

16class BadRequest(DataSolutionsSDKException): 

17 """Exception for Bad Request.""" 

18 

19 def __init__(self, message="Bad Request"): 

20 super().__init__( 

21 message, 

22 status_code=400, 

23 ) 

24 

25 

26class UnauthorizedException(DataSolutionsSDKException): 

27 """Exception for 401 Unauthorized.""" 

28 

29 def __init__(self, message="Unauthorized. Check your API Key."): 

30 super().__init__( 

31 message, 

32 status_code=401, 

33 ) 

34 

35 

36class ForbiddenException(DataSolutionsSDKException): 

37 """Exception for 403 Forbidden.""" 

38 

39 def __init__( 

40 self, 

41 message="Forbidden. Contact Data Solutions if you believe you should have access to this endpoint/data.", 

42 ): 

43 super().__init__( 

44 message, 

45 status_code=403, 

46 ) 

47 

48 

49class NotFoundException(DataSolutionsSDKException): 

50 """Exception for 404 Not Found.""" 

51 

52 def __init__(self, message="Not Found. Is your query correct?"): 

53 super().__init__( 

54 message, 

55 status_code=404, 

56 ) 

57 

58 

59class InternalServerException(DataSolutionsSDKException): 

60 """Exception for 500 Internal Server Error.""" 

61 

62 def __init__(self, message="Internal Server Error"): 

63 super().__init__( 

64 message, 

65 status_code=500, 

66 ) 

67 

68 

69class DataSolutionsAPIException(DataSolutionsSDKException): 

70 """Exception for the API returning an unexpected response.""" 

71 

72 def __init__(self, message="Unexpected response from the API"): 

73 super().__init__( 

74 message, 

75 status_code=0, 

76 ) 

77 

78 

79class UnhandledException(DataSolutionsSDKException): 

80 """Unhandled exception.""" 

81 

82 def __init__( 

83 self, 

84 message="An unhandled exception occured. Please contact the Data Solutions Team.", 

85 details="", 

86 ): 

87 super().__init__((message, details))