Skip to content

Commit

Permalink
slightly improved error handling (#128)
Browse files Browse the repository at this point in the history
* slightly improved error handling

* added missing template file
  • Loading branch information
bbonf authored Nov 28, 2023
1 parent 0376cd2 commit 1088b33
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
5 changes: 1 addition & 4 deletions parent/mailauth/templates/mailauth/login.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{% extends 'base/base.html' %}
{% extends 'base/babex_base.html' %}
{% load i18n %}

{% block content %}
<div class="uu-hero">
<h1>ILS Babylab</h1>
</div>
<div class="uu-container">
<div class="col-12" >
<h2>{% trans 'parent:mailauth:login:header' %}</h2>
Expand Down
9 changes: 6 additions & 3 deletions parent/mailauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class LoginFormView(FormView):
success_url = reverse_lazy("mailauth:sent")

def form_valid(self, form):
# TODO: check the response
gateway(self.request, "/gateway/mailauth/", data=dict(email=form.cleaned_data["email"]))
return super().form_valid(form)
ok, _ = gateway(self.request, "/gateway/mailauth/", data=dict(email=form.cleaned_data["email"]))
if ok:
return super().form_valid(form)
messages.error(self.request, "login failed")
return super().get(self.request)

7 changes: 7 additions & 0 deletions parent/parent/templates/base/babex_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base/base.html' %}
{% block uu-content %}
<div class="uu-hero">
<h1>ILS Babylab</h1>
</div>
{{ block.super }}
{% endblock %}
17 changes: 11 additions & 6 deletions parent/parent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ def gateway(
else:
method = "get"

response = requests.request(
method=method.upper(),
url=settings.API_HOST + url,
headers=headers,
json=data,
)
try:
response = requests.request(
method=method.upper(),
url=settings.API_HOST + url,
headers=headers,
json=data,
)
except Exception:
log.exception("Could not reach gateway")
return False, dict()

if not response.ok:
log.error("Gateway request %s failed: %s", url, response.text)
if len(response.text):
Expand Down
7 changes: 5 additions & 2 deletions parent/parent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ def form_valid(self, form):
# filter out blank fields
fields = {key: value for key, value in form.cleaned_data.items() if value is not None}
signup = Signup(**fields)
signup.put(as_json=True)
return super().form_valid(form)
if signup.put(as_json=True):
return super().form_valid(form)

log.error("Couldn't reach server while processing signup")
return super().get(self.request)


class SignupDone(TemplateView):
Expand Down

0 comments on commit 1088b33

Please sign in to comment.