Coverage for pyngrok/exception.py: 100.00%

# Coverage for pyngrok/exception.py : 100.00%

## 28 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 __author__ = "Alex Laird"

2 __copyright__ = "Copyright 2020, Alex Laird"

3 __version__ = "4.1.0"

4

5

6 class PyngrokError(Exception):

7 """

8 Raised when a general ``pyngrok`` error has occurred.

9 """

10 pass

11

12

13 class PyngrokSecurityError(PyngrokError):

14 """

15 Raised when a ``pyngrok`` security error has occurred.

16 """

17 pass

18

19

20 class PyngrokNgrokInstallError(PyngrokError):

21 """

22 Raised when an error has occurred while downloading and installing the ``ngrok`` binary.

23 """

24 pass

25

26

27 class PyngrokNgrokError(PyngrokError):

28 """

29 Raised when an error occurs interacting directly with the ``ngrok`` binary.

30

31 :var error: A description of the error being thrown.

32 :vartype error: str

33 :var ngrok_logs: The ``ngrok`` logs, which may be useful for debugging the error.

34 :vartype ngrok_logs: list[NgrokLog]

35 :var ngrok_error: The error that caused the ``ngrok`` process to fail.

36 :vartype ngrok_error: str

37 """

38

39 def __init__(self, error, ngrok_logs=None, ngrok_error=None):

40 super(PyngrokNgrokError, self).__init__(error)

41

42 if ngrok_logs is None:

43 ngrok_logs = []

44

45 self.ngrok_logs = ngrok_logs

46 self.ngrok_error = ngrok_error

47

48

49 class PyngrokNgrokHTTPError(PyngrokNgrokError):

50 """

51 Raised when an error occurs making a request to the ``ngrok`` web interface. The ``body``

52 contains the error response received from ``ngrok``.

53

54 :var error: A description of the error being thrown.

55 :vartype error: str

56 :var url: The request URL that failed.

57 :vartype url: str

58 :var status_code: The response status code from ``ngrok``.

59 :vartype status_code: int

60 :var message: The response message from ``ngrok``.

61 :vartype message: str

62 :var headers: The request headers sent to ``ngrok``.

63 :vartype headers: dict[str, str]

64 :var body: The response body from ``ngrok``.

65 :vartype body: str

66 """

67

68 def __init__(self, error, url, status_code, message, headers, body):

69 super(PyngrokNgrokHTTPError, self).__init__(error)

70

71 self.url = url

72 self.status_code = status_code

73 self.message = message

74 self.headers = headers

75 self.body = body

76

77

78 class PyngrokNgrokURLError(PyngrokNgrokError):

79 """

80 Raised when an error occurs when trying to initiate an API request.

81

82 :var error: A description of the error being thrown.

83 :vartype error: str

84 :var reason: The reason for the URL error.

85 :vartype reason: str

86 """

87

88 def __init__(self, error, reason):

89 super(PyngrokNgrokURLError, self).__init__(error)

90

91 self.reason = reason