Skip to content

Commit 0da4c90

Browse files
committed
Adding handling OnlyRelativeLinksAllowed error.
1 parent 34890bb commit 0da4c90

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

codeplain_REST_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class MissingResource(Exception):
2222
pass
2323

2424

25+
class OnlyRelativeLinksAllowed(Exception):
26+
pass
27+
28+
2529
class CodeplainAPI:
2630

2731
def __init__(self, api_key):
@@ -41,9 +45,6 @@ def api_url(self, value):
4145
def post_request(self, endpoint_url, headers, payload):
4246
response = requests.post(endpoint_url, headers=headers, json=payload)
4347

44-
# First check if the response was successful
45-
response.raise_for_status()
46-
4748
try:
4849
response_json = response.json()
4950
except requests.exceptions.JSONDecodeError as e:
@@ -66,6 +67,11 @@ def post_request(self, endpoint_url, headers, payload):
6667
if response_json["error_code"] == 'MissingResource':
6768
raise MissingResource(response_json['message'])
6869

70+
if response_json["error_code"] == 'OnlyRelativeLinksAllowed':
71+
raise OnlyRelativeLinksAllowed(response_json['message'])
72+
73+
response.raise_for_status()
74+
6975
return response_json
7076

7177

0 commit comments

Comments
 (0)