Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit 3067809

Browse files
committed
exception.py: differentiate between bridge and farmer errors.
use new BridgeError class and make StorjBridgeApiError an alias of it. use new FarmerError class and make StorjFarmerError an alias of it.
1 parent 88eb2a4 commit 3067809

2 files changed

Lines changed: 59 additions & 7 deletions

File tree

storj/exception.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,65 @@
22
"""Storj exception module."""
33

44

5-
class StorjBridgeApiError(Exception):
6-
"""Generic Storj exception."""
7-
pass
5+
class BridgeError(RuntimeError):
6+
"""Storj bridge runtime exception.
87
8+
Attributes:
9+
message (str): error message.
10+
"""
11+
12+
def __init__(self, code='', message=''):
13+
super(RuntimeError, self).__init__()
14+
15+
self.code = code
16+
self.message = message
17+
18+
19+
class FarmerError(RuntimeError):
20+
"""Storj farmer runtime exception.
21+
22+
Attributes:
23+
code (int): error code.
24+
message (str): error message.
25+
"""
926

10-
class StorjFarmerError(Exception):
11-
"""Storj Farmer Exception"""
1227
SUPPLIED_TOKEN_NOT_ACCEPTED = 10002
1328
CALCULATED_HASH_NOT_MATCH_EXPECTED_RESULT = 10003
14-
pass
29+
30+
def __init__(self, code, message=''):
31+
super(RuntimeError, self).__init__()
32+
33+
self.code = code
34+
self.message = message
35+
36+
def __str__(self):
37+
"""Returns a string representation of this error.
38+
39+
Returns:
40+
str: string representation of this error.
41+
"""
42+
return '[%s] %s' % (self.code, self.message)
43+
44+
45+
class SuppliedTokenNotAcceptedError(FarmerError):
46+
""""""
47+
48+
CODE = 10002
49+
50+
def __init__(self):
51+
super(SuppliedTokenNotAcceptedError, self).__init__(
52+
code=SuppliedTokenNotAcceptedError.CODE)
53+
54+
55+
class HashMismatchError(FarmerError):
56+
""""""
57+
58+
CODE = 10003
59+
60+
def __init__(self):
61+
super(HashMismatchError, self).__init__(
62+
code=HashMismatchError.CODE)
63+
64+
65+
StorjBridgeApiError = BridgeError
66+
StorjFarmerError = FarmerError

tests/unit/http_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_bucket_get_error(self):
129129

130130
self.mock_request.side_effect = mock_error
131131

132-
with pytest.raises(exception.StorjBridgeApiError):
132+
with pytest.raises(exception.BridgeError):
133133
self.client.bucket_get('error')
134134

135135
self.mock_request.assert_called_once_with(

0 commit comments

Comments
 (0)