Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slightly improved error handling #128

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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