Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Desk: add dedicated error handler #1434

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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)

Check warning on line 922 in atlassian/service_desk.py

View check run for this annotation

Codecov / codecov/patch

atlassian/service_desk.py#L922

Added line #L922 was not covered by tests

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()

Check warning on line 930 in atlassian/service_desk.py

View check run for this annotation

Codecov / codecov/patch

atlassian/service_desk.py#L925-L930

Added lines #L925 - L930 were not covered by tests
else:
raise HTTPError(error_msg, response=response)

Check warning on line 932 in atlassian/service_desk.py

View check run for this annotation

Codecov / codecov/patch

atlassian/service_desk.py#L932

Added line #L932 was not covered by tests