atlassian-python-api: Implement better error handling
For some reason the JIRA server is randomly throwing authentication errors. I’ll take this up with my IT group. however the python API doesn’t throw any exceptions it just returns a string of the html of the error. For example if I do
jira = Jira(
url=host,
username=user,
password=passwd)
data = jira.jql(q)
if there is an auth error then data comes back as the string content of the html error from jira. It would be nice if the python api would just detect this internally and throw some kind of exception. Otherwise there is a cryptic error later on where I try to index the data structure and get a failure because it is not the correct type.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 15 (11 by maintainers)
You would like to incorporate Atlassian specific errors into the raised exception, right? For instance making it clear that a HTTP 403 response on a GET /rest/api/2/permissions request really means that the user doesn’t have administrative privileges?
If so, then I suggest making a base exception class such as AtlassianException or similar, and a subclass exception for all of the different types of errors that can occur. Using the example above, let’s say we have an exception class AtlassianPermissionError that is subclassed from AtlassianException. The
get_all_permissions
method in the Jira module could then be rewritten to the following in order to translate and convey the correct meaning of the HTTP 403 response.The advantages of doing it this way is that the original exception is preserved and that the correct information (i.e. lacking administrative privileges) is conveyed to the user and/or developer. The disadvantage is that exception chaining requires Python 3. However, as Python 2 is EOL, I assume this isn’t a problem.