Skip to content

Commit

Permalink
Merge pull request #86 from rapidpro/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Erin Mullaney committed Oct 29, 2015
2 parents f94d566 + 77e2525 commit 4ac4596
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tracpro/orgs_ext/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseBadRequest
from django.shortcuts import render

from requests import HTTPError

Expand All @@ -20,15 +20,19 @@ def process_exception(self, request, exception):
response = exception.caused_by.response
if response is not None:
if response.status_code == 403:
return HttpResponseBadRequest(
return self.rapidpro_error(
request,
_("Org does not have a valid API Key. "
"Please edit the org through Site Manage or contact your administrator."))
"Please edit the org through Site Manage or contact your administrator.")
)

elif response.status_code >= 500:
return HttpResponseBadRequest(rapidpro_connection_error_string)
return self.rapidpro_error(request, rapidpro_connection_error_string)

elif isinstance(exception, TembaConnectionError):
return HttpResponseBadRequest(
rapidpro_connection_error_string)
return self.rapidpro_error(request, rapidpro_connection_error_string)

return None

def rapidpro_error(self, request, message):
return render(request, "rapidpro_error.html", {"error_message": message}, status=400)
7 changes: 7 additions & 0 deletions tracpro/templates/rapidpro_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "frame.html" %}

{% block content %}
<div>
{{ error_message }}
</div>
{% endblock %}

0 comments on commit 4ac4596

Please sign in to comment.