Coverage for ghost/exceptions.py: 94%

1 import pprint

2

3 __all__ = [

4 "BaseGhostException",

5 "GhostResponseException",

6 "GhostUnknownException",

7 "GhostJSONException",

8 "GhostResourceNotFoundException",

9 "GhostWrongApiError",

10]

11

12

13 class BaseGhostException(Exception):

14 """

15 Base, inherit this cls

16 """

17

18 def __init__(

19 self, status_code, error_type=None, error_message="", *a, exception=None

20 ):

21 super().__init__(

22 str(status_code), error_type, error_message, *a

23 ) # -> self.args

24

25 self.status_code = str(status_code)

26 self.error_type = error_type

27 self.error_message = error_message

28 self.exception = exception

29

30 def __str__(self):

31 return " - ".join(self.args) + "\n" + pprint.pformat(self.exception)

32

33

34 class GhostResponseException(BaseGhostException):

35 """

36 -> from JSON['errors']

37 """

38

39

40 class GhostUnknownException(BaseGhostException):

41 """

42 -> if JSON but no errors key

43 """

44

45

46 class GhostJSONException(BaseGhostException):

47 """

48 -> if JSON could not be parsed

49 """

50

51

52 class GhostResourceNotFoundException(BaseGhostException):

53 """

54 -> call correct but just no data

55 """

56

57

58 class GhostWrongApiError(BaseGhostException):

59 """

60 -> content api used instead of admin

61 """