Skip to content

Commit

Permalink
Service Desk: add dedicated error handler (#1434)
Browse files Browse the repository at this point in the history
Co-authored-by: Alfredo Altamirano <[email protected]>
  • Loading branch information
Ahuahuachi and Ahuahuachi authored Aug 29, 2024
1 parent 1df1ad4 commit 388a340
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions atlassian/service_desk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# coding=utf-8
import logging

from requests import HTTPError

from .rest_client import AtlassianRestAPI

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -909,3 +911,22 @@ def create_request_type(

url = "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id)
return self.post(url, headers=self.experimental_headers, data=data)

def raise_for_status(self, response):
"""
Checks the response for an error status and raises an exception with the error message provided by the server
:param response:
:return:
"""
if response.status_code == 401 and response.headers.get("Content-Type") != "application/json;charset=UTF-8":
raise HTTPError("Unauthorized (401)", response=response)

if 400 <= response.status_code < 600:
try:
j = response.json()
error_msg = j["errorMessage"]
except Exception as e:
log.error(e)
response.raise_for_status()
else:
raise HTTPError(error_msg, response=response)

0 comments on commit 388a340

Please sign in to comment.