Skip to content

Commit

Permalink
Merge pull request #1 from Uninett/error-handling
Browse files Browse the repository at this point in the history
Change error handling to match Argus
  • Loading branch information
johannaengland authored Feb 1, 2023
2 parents dbae7f2 + ef4b943 commit 03a2437
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/argus_ticket_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
from jira import JIRA
from markdownify import markdownify

from argus.incident.ticket.base import TicketPlugin, TicketPluginException
from argus.incident.ticket.base import (
TicketClientException,
TicketCreationException,
TicketPlugin,
TicketPluginException,
TicketSettingsException,
)

LOG = logging.getLogger(__name__)

Expand All @@ -21,25 +27,19 @@ class JiraPlugin(TicketPlugin):
def import_settings(cls):
try:
endpoint, authentication, ticket_information = super().import_settings()
except ValueError as e:
LOG.exception("Could not import settings for ticket plugin.")
raise TicketPluginException(f"Jira: {e}")
except TicketSettingsException as e:
LOG.exception(e)
raise TicketSettingsException(f"Jira: {e}")

if "token" not in authentication.keys():
LOG.error(
"Jira: No token can be found in the authentication information. Please update the setting 'TICKET_AUTHENTICATION_SECRET'."
)
raise TicketPluginException(
"Jira: No token can be found in the authentication information. Please update the setting 'TICKET_AUTHENTICATION_SECRET'."
)
authentication_error = "Jira: No token can be found in the authentication information. Please update the setting 'TICKET_AUTHENTICATION_SECRET'."
LOG.error(authentication_error)
raise TicketSettingsException(authentication_error)

if "project_key_or_id" not in ticket_information.keys():
LOG.error(
"Jira: No project key or id can be found in the ticket information. Please update the setting 'TICKET_INFORMATION'."
)
raise TicketPluginException(
"Jira: No project key or id can be found in the ticket information. Please update the setting 'TICKET_INFORMATION'."
)
project_key_id_error = "Jira: No project key or id can be found in the ticket information. Please update the setting 'TICKET_INFORMATION'."
LOG.error(project_key_id_error)
raise TicketSettingsException(project_key_id_error)

return endpoint, authentication, ticket_information

Expand Down Expand Up @@ -94,8 +94,9 @@ def create_client(endpoint, authentication):
token_auth=authentication["token"],
)
except Exception as e:
LOG.exception("Jira: Client could not be created.")
raise TicketPluginException(f"Jira: {e}")
client_error = "Jira: Client could not be created."
LOG.exception(client_error)
raise TicketClientException(client_error)
else:
return client

Expand Down Expand Up @@ -136,7 +137,8 @@ def create_ticket(cls, serialized_incident: dict):
try:
ticket = client.create_issue(fields=fields)
except Exception as e:
LOG.exception("Jira: Ticket could not be created.")
raise TicketPluginException(f"Jira: {e}")
ticket_error = "Jira: Ticket could not be created."
LOG.exception(ticket_error)
raise TicketPluginException(f"{ticket_error} {e}")
else:
return ticket.permalink()

0 comments on commit 03a2437

Please sign in to comment.