Skip to content

Commit 388a340

Browse files
authored
Service Desk: add dedicated error handler (#1434)
Co-authored-by: Alfredo Altamirano <Ahuahuachi@users.noreply.github.com>
1 parent 1df1ad4 commit 388a340

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

atlassian/service_desk.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# coding=utf-8
22
import logging
33

4+
from requests import HTTPError
5+
46
from .rest_client import AtlassianRestAPI
57

68
log = logging.getLogger(__name__)
@@ -909,3 +911,22 @@ def create_request_type(
909911

910912
url = "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id)
911913
return self.post(url, headers=self.experimental_headers, data=data)
914+
915+
def raise_for_status(self, response):
916+
"""
917+
Checks the response for an error status and raises an exception with the error message provided by the server
918+
:param response:
919+
:return:
920+
"""
921+
if response.status_code == 401 and response.headers.get("Content-Type") != "application/json;charset=UTF-8":
922+
raise HTTPError("Unauthorized (401)", response=response)
923+
924+
if 400 <= response.status_code < 600:
925+
try:
926+
j = response.json()
927+
error_msg = j["errorMessage"]
928+
except Exception as e:
929+
log.error(e)
930+
response.raise_for_status()
931+
else:
932+
raise HTTPError(error_msg, response=response)

0 commit comments

Comments
 (0)