Skip to content

Commit b948dd6

Browse files
committed
Add custom exception
1 parent a9c01a1 commit b948dd6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

nocodb/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class NocoDBAPIError(Exception):
2+
def __init__(self, message, status_code, response_json=None, response_text=None):
3+
super().__init__(message)
4+
self.status_code = status_code
5+
self.response_json = response_json
6+
self.response_text = response_text

nocodb/infra/requests_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from ..api import NocoDBAPI
99
from ..utils import get_query_params
10+
from ..exceptions import NocoDBAPIError
1011

1112
import requests
1213

@@ -22,7 +23,21 @@ def __init__(self, auth_token: AuthToken, base_uri: str):
2223

2324
def _request(self, method, url, *args, **kwargs):
2425
response = self.__session.request(method, url, *args, **kwargs)
25-
response.raise_for_status()
26+
try:
27+
response.raise_for_status()
28+
except requests.exceptions.HTTPError as http_error:
29+
response_json = None
30+
try:
31+
response_json = response.json()
32+
except requests.exceptions.JSONDecodeError:
33+
...
34+
raise NocoDBAPIError(
35+
message=str(http_error),
36+
status_code=http_error.response.status_code,
37+
response_json=response_json,
38+
response_text=response.text
39+
)
40+
2641
return response
2742

2843
def table_row_list(

0 commit comments

Comments
 (0)