Skip to content

Commit c67b632

Browse files
committed
refactored exception formatting and added tests
1 parent 7dd06cd commit c67b632

21 files changed

+262
-651
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
.pytest_cache/
3-
*.egg
3+
*.egg
4+
tests/.env
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from requests import Response
2+
3+
4+
class SandboxRestException(Exception):
5+
""" Base Exception Class inside Rest client class """
6+
def __init__(self, msg: str, response: Response = None):
7+
self.msg = msg
8+
self.response = response
9+
10+
def __str__(self):
11+
return self._format_err_msg(self.msg, self.response)
12+
13+
def _format_err_msg(self, custom_err_msg="Failed Api Call", response: Response = None) -> str:
14+
err_msg = f"Sandbox API Error: {custom_err_msg}"
15+
16+
if response:
17+
err_msg += f"\n{self._format_response_msg(response)}"
18+
19+
@staticmethod
20+
def _format_response_msg(response: Response):
21+
return (f"Response: {response.status_code}, Reason: {response.reason}\n"
22+
f"Request URL: {response.request.url}\n"
23+
f"Request Headers: {response.request.headers}")
24+
25+
26+
class SandboxRestAuthException(SandboxRestException):
27+
""" Failed auth action """
28+
pass

cloudshell/sandbox_rest/helpers/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
-191 Bytes
Binary file not shown.
Binary file not shown.

cloudshell/sandbox_rest/helpers/polling_helpers.py

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)