Skip to content

Commit a54c9a5

Browse files
authored
Merge pull request #38 from bugout-dev/fix-network-errors-pr
Defined network error as 599
2 parents e321581 + de59c0a commit a54c9a5

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.1.19"
10+
__version__ = "0.1.20"
1111

1212
__all__ = (
1313
"__author__",

bugout/calls.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ def make_request(method: Method, url: str, **kwargs) -> Any:
1111
response = requests.request(method.value, url=url, **kwargs)
1212
response.raise_for_status()
1313
except requests.exceptions.RequestException as err:
14-
response = err.response
14+
r = err.response
1515
if not err.response:
1616
# Connection errors, timepouts, etc...
17-
raise BugoutResponseException("Network error", detail=str(err))
18-
if response.headers.get("Content-Type") == "application/json":
19-
exception_detail = response.json()["detail"]
17+
raise BugoutResponseException(
18+
"Network error", status_code=599, detail=str(err)
19+
)
20+
if r.headers.get("Content-Type") == "application/json":
21+
exception_detail = r.json()["detail"]
2022
else:
21-
exception_detail = response.text
23+
exception_detail = r.text
2224
raise BugoutResponseException(
2325
"An exception occurred at Bugout API side",
24-
status_code=response.status_code,
26+
status_code=r.status_code,
2527
detail=exception_detail,
2628
)
2729
except Exception as e:
28-
raise BugoutUnexpectedResponse({str(e)})
30+
raise BugoutUnexpectedResponse(str(e))
2931
return response.json()
3032

3133

bugout/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BugoutResponseException(Exception):
2121
def __init__(
2222
self,
2323
message,
24-
status_code: Optional[int] = None,
24+
status_code: int,
2525
detail: Optional[Any] = None,
2626
) -> None:
2727
super().__init__(message)

0 commit comments

Comments
 (0)