Skip to content

Commit 62495f9

Browse files
authored
fix(fabricerror): make http code mandatory (#8)
1 parent 11a5fc2 commit 62495f9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/core/tests/test_fabric_error.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
def test_basic_error():
66
basic_error = FabricError()
77
basic_error.name = "BasicError"
8-
basic_error.description = "This is a basic test error"
8+
basic_error.description = "This is a default test error"
99
basic_error.return_value = -1
1010

1111
basic_error_dict = dict(basic_error)
1212

1313
assert 'name' in basic_error_dict
1414
assert 'description' in basic_error_dict
15+
assert basic_error_dict['description'] == "This is a default test error"
1516
assert 'return_value' in basic_error_dict
17+
assert basic_error_dict['return_value'] == -1
18+
assert 'http_code' in basic_error_dict
19+
assert basic_error_dict['http_code'] == 500
1620

1721
def test_full_error():
1822
basic_error = FabricError(context={'a': 'a'}, http_code=500, name="FullError")

src/core/ydata/core/error/fabric_error.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _camelcased(value: str) -> str:
1111
class FabricError(Exception):
1212
context: Optional[dict[str, str]]
1313
description: str
14-
http_code: Optional[int]
14+
http_code: int = 500
1515
name: Optional[str]
1616
return_value: int
1717

@@ -21,7 +21,8 @@ def __init__(
2121
http_code: Optional[int] = None,
2222
name: Optional[str] = None):
2323
self.context = context
24-
self.http_code = http_code
24+
if http_code:
25+
self.http_code = http_code
2526
self.name = name
2627

2728
def __iter__(self):
@@ -36,7 +37,7 @@ def __iter__(self):
3637
def __str__(self) -> str:
3738
return f'''
3839
{self.__class__.__name__}(name={self.name}, context={self.context}, description={self.description}, \
39-
return_value={self.return_value})
40+
http_code={self.http_code}, return_value={self.return_value})
4041
'''
4142

4243
def __repr__(self) -> str:

0 commit comments

Comments
 (0)