forked from iexbase/tron-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
116 lines (74 loc) · 2.28 KB
/
exceptions.py
File metadata and controls
116 lines (74 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# --------------------------------------------------------------------
# Copyright (c) iEXBase. All rights reserved.
# Licensed under the MIT License.
# See License.txt in the project root for license information.
# --------------------------------------------------------------------
class TronError(Exception):
"""Base class for TronAPI exceptions."""
class InvalidTronError(TronError):
"""Raised Tron Error"""
class FallbackNotFound(Exception):
"""
Raised when fallback function doesn't exist in contract.
"""
pass
class MismatchedABI(Exception):
"""
Raised when an ABI does not match with supplied parameters, or when an
attempt is made to access a function/event that does not exist in the ABI.
"""
pass
class InvalidAddress(ValueError):
"""
The supplied address does not have a valid checksum, as defined in EIP-55
"""
pass
class NoABIFunctionsFound(AttributeError):
"""
Raised when an ABI doesn't contain any functions.
"""
pass
class ValidationError(Exception):
"""
Raised when a supplied value is invalid.
"""
pass
class TransportError(TronError):
"""Base exception for transport related errors.
This is mainly for cases where the status code denotes an HTTP error, and
for cases in which there was a connection error.
"""
@property
def status_code(self):
return self.args[0]
@property
def error(self):
return self.args[1]
@property
def info(self):
return self.args[2]
@property
def url(self):
return self.args[3]
class HttpError(TransportError):
"""Exception for errors occurring when connecting, and/or making a request"""
class BadRequest(TransportError):
"""Exception for HTTP 400 errors."""
class NotFoundError(TransportError):
"""Exception for HTTP 404 errors."""
class ServiceUnavailable(TransportError):
"""Exception for HTTP 503 errors."""
class GatewayTimeout(TransportError):
"""Exception for HTTP 503 errors."""
class TimeExhausted(Exception):
"""
Raised when a method has not retrieved the desired result
within a specified timeout.
"""
pass
HTTP_EXCEPTIONS = {
400: BadRequest,
404: NotFoundError,
503: ServiceUnavailable,
504: GatewayTimeout,
}