Skip to content

Commit 4a6a595

Browse files
author
Gonchik Tsymzhitov
committed
Jira: Add error handler for method get issue security field scheme method
1 parent e0eec64 commit 4a6a595

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

atlassian/jira.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# coding=utf-8
22
import logging
33
import re
4+
5+
from requests import HTTPError
6+
47
from .rest_client import AtlassianRestAPI
8+
from .errors import (
9+
ApiError,
10+
ApiNotFoundError,
11+
ApiPermissionError,
12+
ApiValueError,
13+
ApiConflictError
14+
)
515

616
log = logging.getLogger(__name__)
717

@@ -1730,11 +1740,26 @@ def get_project_issue_security_scheme(self, project_id_or_key, only_levels=False
17301740
:return: list
17311741
"""
17321742
url = 'rest/api/2/project/{}/issuesecuritylevelscheme'.format(project_id_or_key)
1733-
1734-
if only_levels is True:
1735-
return self.get(url).get('levels')
1736-
else:
1737-
return self.get(url)
1743+
response = None
1744+
try:
1745+
response = self.get(url)
1746+
except HTTPError as e:
1747+
if e.response.status_code == 401:
1748+
raise ApiPermissionError(
1749+
"Returned if the user is not logged in.",
1750+
reason=e)
1751+
elif e.response.status_code == 403:
1752+
raise ApiPermissionError(
1753+
"Returned if the project is visible for calling user, but the user doesn't have administrative permissions",
1754+
reason=e)
1755+
elif e.response.status_code == 404:
1756+
raise ApiNotFoundError(
1757+
"Returned if the project does not exist, or is not visible to the calling user",
1758+
reason=e)
1759+
raise
1760+
if only_levels is True and response:
1761+
return response.get('levels') or None
1762+
return response
17381763

17391764
# Priority Schemes
17401765
def get_all_priority_schemes(self, start=0, limit=100, expand=None):

examples/jira/jira-add-issues-to-sprint.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@
99
username='admin',
1010
password='admin')
1111

12-
resp = jira.add_issues_to_sprint(
13-
sprint_id=sprint_id,
14-
issues=issues_lst
15-
)
12+
resp = jira.add_issues_to_sprint(sprint_id=sprint_id,
13+
issues=issues_lst)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
import logging
3+
from atlassian import Jira
4+
from pprint import pprint
5+
6+
""" How to get server info with health check"""
7+
8+
jira = Jira(
9+
url="https://jira.example.com/",
10+
username='gonchik.tsymzhitov',
11+
password='********')
12+
13+
log = logging.getLogger("com.gonchik.python.scripts.example")
14+
logging.basicConfig(level=logging.ERROR)
15+
16+
projects = jira.get_all_projects()
17+
for project in projects:
18+
project_key = project.get("key")
19+
try:
20+
value = jira.get_project_issue_security_scheme(project_key).get("name") or "None"
21+
except Exception as e:
22+
log.error(e)
23+
value = "None"
24+
print(project_key + " has issue security scheme " + value)

0 commit comments

Comments
 (0)