Skip to content

Commit 4fbfcc6

Browse files
Add the response object to the custom error classes
1 parent e478ea2 commit 4fbfcc6

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

ReversingLabs/SDK/helper.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,80 +26,109 @@
2626
ADVANCED_SEARCH_SORTING_CRITERIA = ("sha1", "firstseen", "threatname", "sampletype", "filecount", "size")
2727

2828

29+
class WrongInputError(Exception):
30+
def __init__(self, message="This input type is not allowed"):
31+
super(WrongInputError, self).__init__(message)
32+
33+
2934
class NotFoundError(Exception):
30-
def __init__(self, message="Not found. No reference was found for this input"):
35+
def __init__(self, response_object, message="Not found. No reference was found for this input"):
3136
super(NotFoundError, self).__init__(message)
3237

38+
self.response_object = response_object
39+
3340

3441
class NoFileTypeError(Exception):
35-
def __init__(self, message="There is no determinable file type"):
42+
def __init__(self, response_object, message="There is no determinable file type"):
3643
super(NoFileTypeError, self).__init__(message)
3744

38-
39-
class WrongInputError(Exception):
40-
def __init__(self, message="This input type is not allowed"):
41-
super(WrongInputError, self).__init__(message)
45+
self.response_object = response_object
4246

4347

4448
class UnauthorizedError(Exception):
45-
def __init__(self, message="The provided credentials are invalid"):
49+
def __init__(self, response_object, message="The provided credentials are invalid"):
4650
super(UnauthorizedError, self).__init__(message)
4751

52+
self.response_object = response_object
53+
4854

4955
class ForbiddenError(Exception):
50-
def __init__(self, message="The provided credentials do not have the required rights to access this resource"):
56+
def __init__(self, response_object,
57+
message="The provided credentials do not have the required rights to access this resource"):
5158
super(ForbiddenError, self).__init__(message)
5259

60+
self.response_object = response_object
61+
5362

5463
class BadRequestError(Exception):
55-
def __init__(self, message="Bad request created"):
64+
def __init__(self, response_object, message="Bad request created"):
5665
super(BadRequestError, self).__init__(message)
5766

67+
self.response_object = response_object
68+
5869

5970
class RequestTimeoutError(Exception):
60-
def __init__(self, message="Request timed out"):
71+
def __init__(self, response_object, message="Request timed out"):
6172
super(RequestTimeoutError, self).__init__(message)
6273

74+
self.response_object = response_object
75+
6376

6477
class ConflictError(Exception):
65-
def __init__(self, message="Can't complete the request due to a conflict"):
78+
def __init__(self, response_object, message="Can't complete the request due to a conflict"):
6679
super(ConflictError, self).__init__(message)
6780

81+
self.response_object = response_object
82+
6883

6984
class RequestTooLargeError(Exception):
70-
def __init__(self, message="The request is too large"):
85+
def __init__(self, response_object, message="The request is too large"):
7186
super(RequestTooLargeError, self).__init__(message)
7287

88+
self.response_object = response_object
89+
7390

7491
class InternalServerError(Exception):
75-
def __init__(self, message="Internal server error"):
92+
def __init__(self, response_object, message="Internal server error"):
7693
super(InternalServerError, self).__init__(message)
7794

95+
self.response_object = response_object
96+
7897

7998
class BadGatewayError(Exception):
80-
def __init__(self, message="The server received an invalid response from another server"):
99+
def __init__(self, response_object, message="The server received an invalid response from another server"):
81100
super(BadGatewayError, self).__init__(message)
82101

102+
self.response_object = response_object
103+
83104

84105
class ServiceUnavailableError(Exception):
85-
def __init__(self, message="Service unavailable"):
106+
def __init__(self, response_object, message="Service unavailable"):
86107
super(ServiceUnavailableError, self).__init__(message)
87108

109+
self.response_object = response_object
110+
88111

89112
class NotAllowedError(Exception):
90-
def __init__(self, message="This method is not allowed"):
113+
def __init__(self, response_object, message="This method is not allowed"):
91114
super(NotAllowedError, self).__init__(message)
92115

116+
self.response_object = response_object
117+
93118

94119
class TooManyRequestsError(Exception):
95-
def __init__(self, message="Too many requests. Your quota limit might be reached"):
120+
def __init__(self, response_object, message="Too many requests. Your quota limit might be reached"):
96121
super(TooManyRequestsError, self).__init__(message)
97122

123+
self.response_object = response_object
124+
98125

99126
class NotAcceptableError(Exception):
100-
def __init__(self, message="This content is not acceptable"):
127+
def __init__(self, response_object, message="This content is not acceptable"):
101128
super(NotAcceptableError, self).__init__(message)
102129

130+
self.response_object = response_object
131+
103132

104133
class CloudDeepScanException(Exception):
105134
"""Base exception for the clouddeepscan module

ReversingLabs/SDK/ticloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _raise_on_error(self, response):
179179
return
180180
if exception == NotFoundError and self._allow_none_return:
181181
return None
182-
raise exception
182+
raise exception(response_object=response)
183183

184184

185185
class FileReputation(TiCloudAPI):

0 commit comments

Comments
 (0)