Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Gracefully handle basic form initialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Feb 18, 2016
1 parent 4e94347 commit b056144
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sentry_jira/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class JIRAPlugin(IssuePlugin):
project_conf_template = "sentry_jira/project_conf_form.html"
new_issue_form = JIRAIssueForm
create_issue_template = 'sentry_jira/create_jira_issue.html'
plugin_misconfigured_template = 'sentry_jira/plugin_misconfigured.html'

# Adding resource links for forward compatibility, still need to integrate
# into existing `project_conf.html` template.
Expand Down Expand Up @@ -168,13 +169,20 @@ def view(self, request, group, **kwargs):
Event.objects.bind_nodes([event], 'data')

# Added the ignored_fields to the new_issue_form call
form = self.new_issue_form(
request.POST or None,
initial=self.get_initial_form_data(request, group, event),
jira_client=self.get_jira_client(group.project),
project_key=self.get_option('default_project', group.project),
ignored_fields=self.get_option("ignored_fields", group.project)
)
try:
form = self.new_issue_form(
request.POST or None,
initial=self.get_initial_form_data(request, group, event),
jira_client=self.get_jira_client(group.project),
project_key=self.get_option('default_project', group.project),
ignored_fields=self.get_option("ignored_fields", group.project)
)
except JIRAError as e:
context = {
'errorMessages': e.json.get('errorMessages', []) if e.json else [],
'title': self.get_new_issue_title(),
}
return self.render(self.plugin_misconfigured_template, context)

# to allow the form to be submitted, but ignored so that dynamic fields
# can change if the issuetype is different
Expand Down
15 changes: 15 additions & 0 deletions sentry_jira/templates/sentry_jira/plugin_misconfigured.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "sentry/plugins/bases/issue/create_issue.html" %}

{% block main %}
<p>There is an error with the Jira configuration stored for your project.</p>
<ul>
{% if errorMessages %}
{% for message in errorMessages %}
<li>{{ message }}</li>
{% endfor %}
{% else %}
<li>An unknown error occurred while communicating with Jira.</li>
{% endif %}
</ul>
<p>You may wish to double check your <a href="{% url 'sentry-configure-project-plugin' project.organization.slug project.slug plugin.slug %}">configuration</a>.</p>
{% endblock %}
17 changes: 17 additions & 0 deletions tests/sentry_jira/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,23 @@ def test_create_issue_saves(self):
},
}

@responses.activate
def test_create_issue_with_fetch_errors(self):
project = self.project
plugin = self.plugin

plugin.set_option('username', 'foo', project)
plugin.set_option('password', 'bar', project)
plugin.set_option('instance_url', 'https://getsentry.atlassian.net', project)
plugin.set_option('default_project', 'SEN', project)

self.login_as(self.user)

response = self.client.get(self.action_path)

assert response.status_code == 200, vars(response)
self.assertTemplateUsed(response, 'sentry_jira/plugin_misconfigured.html')

def test_configure_renders(self):
self.login_as(self.user)
with jira_mock():
Expand Down

0 comments on commit b056144

Please sign in to comment.