Skip to content

Commit edf5dab

Browse files
Handling warnings from server
1 parent 7c7dcaf commit edf5dab

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pt_cli/connect.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
class Error(Exception):
1717
"""docstring for Error"""
1818
def __init__(self, msg):
19-
self.args = (f"{type(self).__name__}: {msg}",)
19+
if isinstance(msg, list):
20+
self.args = (f"{type(self).__name__}: \n{chr(10).join(msg)}",)
21+
else:
22+
self.args = (f"{type(self).__name__}: {msg}",)
2023
sys.exit(self)
2124

2225
class BadRequestError(Error):
2326
"""docstring for BadRequestError"""
2427

28+
class BadRequestWarning(Error):
29+
"""docstring for BadRequestError"""
30+
2531
class OAuthNego():
2632
"""
2733
The base class to create python client that is able to
@@ -87,9 +93,11 @@ def connect(self, r_get):
8793
def maybe_json(self, data):
8894
try:
8995
loads = json.loads(data)
90-
# logger.info(f"\n\n{type(data)}\n{type(loads)}\n\n")
96+
# logger.info(f"\n\n{loads}\n\n")
9197
if isinstance(loads, dict) and loads.get("DB_ACTION_ERROR"):
9298
raise BadRequestError(loads.get("DB_ACTION_ERROR"))
99+
if isinstance(loads, dict) and loads.get("DB_ACTION_WARNING"):
100+
raise BadRequestWarning(loads.get("DB_ACTION_WARNING"))
93101
self.data_type = 'json'
94102
return loads
95103
except json.decoder.JSONDecodeError:

0 commit comments

Comments
 (0)