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

Add IR failure template and handle failure #324

Merged
merged 21 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a81f680
Add IR failure template and handle failure
JamesGardiner Sep 30, 2020
f0e6b8d
Merge branch 'master' into individual-response-error-page
JamesGardiner Sep 30, 2020
a763747
update translations
JamesGardiner Sep 30, 2020
c6aa1fe
Merge branch 'individual-response-error-page' of github.com:ONSdigita…
JamesGardiner Sep 30, 2020
6f35cf2
Merge branch 'master' into individual-response-error-page
JamesGardiner Sep 30, 2020
a2bbf90
correct test strings
JamesGardiner Sep 30, 2020
ebb385b
Merge branch 'individual-response-error-page' of github.com:ONSdigita…
JamesGardiner Sep 30, 2020
f18f331
Move error handling to error module
JamesGardiner Sep 30, 2020
b6f8f1f
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 1, 2020
d0dbfeb
fix unused import
JamesGardiner Oct 1, 2020
1e90ffe
Merge branch 'individual-response-error-page' of github.com:ONSdigita…
JamesGardiner Oct 1, 2020
7b9dc99
Use _render_error_page
JamesGardiner Oct 1, 2020
66757ed
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 2, 2020
dd3818d
Use data-qa selector and remove edge check
JamesGardiner Oct 2, 2020
b89e613
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 2, 2020
60fe358
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 2, 2020
b854ade
Update templates/errors/fulfilment-request.html
JamesGardiner Oct 2, 2020
3d648c5
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 2, 2020
7f9021f
POST no longer allowed on IR endpoint
JamesGardiner Oct 2, 2020
fe311df
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 5, 2020
a27efc9
Merge branch 'master' into individual-response-error-page
JamesGardiner Oct 5, 2020
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
31 changes: 28 additions & 3 deletions app/routes/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Blueprint, request
from flask import session as cookie_session
from flask.helpers import url_for
from flask_login import current_user
from flask_wtf.csrf import CSRFError
from sdc.crypto.exceptions import InvalidTokenException
Expand All @@ -14,6 +15,7 @@
from app.helpers.template_helpers import render_template
from app.settings import EQ_SESSION_ID
from app.submitter.submission_failed import SubmissionFailedException
from app.views.handlers.individual_response import FulfilmentRequestFailedException

logger = get_logger()

Expand All @@ -35,13 +37,12 @@ def log_error(error, status_code):
)


def _render_error_page(status_code, template=None):
def _render_error_page(status_code, template=None, **kwargs):
handle_language()
template = template or status_code
using_edge = request.user_agent.browser == "edge"

return (
render_template(template=f"errors/{template}", using_edge=using_edge),
render_template(template=f"errors/{template}", **kwargs),
status_code,
)

Expand Down Expand Up @@ -92,3 +93,27 @@ def internal_server_error(error=None):
def http_exception(error):
log_error(error, error.code)
return _render_error_page(error.code)


@errors_blueprint.app_errorhandler(FulfilmentRequestFailedException)
MebinAbraham marked this conversation as resolved.
Show resolved Hide resolved
def fulfilment_request_failed(error):
logger.exception(
"An individual response fulfilment request failed",
url=request.url,
status_code=500,
)

if "mobile_number" in request.args:
blueprint_method = (
"individual_response.individual_response_text_message_confirm"
)
else:
blueprint_method = (
"individual_response.individual_response_post_address_confirm"
)

retry_url = url_for(
blueprint_method, list_item_id=request.view_args["list_item_id"], **request.args
)

return _render_error_page(500, template="fulfilment-request", retry_url=retry_url)
63 changes: 36 additions & 27 deletions app/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-09-24 15:43+0100\n"
"POT-Creation-Date: 2020-09-30 12:27+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -328,107 +328,107 @@ msgstr ""
msgid "Error: {page_title}"
msgstr ""

#: app/views/handlers/individual_response.py:223
#: app/views/handlers/individual_response.py:224
msgid "How would you like <em>{person_name}</em> to receive a separate census?"
msgstr ""

#: app/views/handlers/individual_response.py:229
#: app/views/handlers/individual_response.py:230
msgid ""
"For someone to complete a separate census, we need to send them an "
"individual access code."
msgstr ""

#: app/views/handlers/individual_response.py:232
#: app/views/handlers/individual_response.py:233
msgid "Select how to send access code"
msgstr ""

#: app/views/handlers/individual_response.py:242
#: app/views/handlers/individual_response.py:243
msgid "Text message"
msgstr ""

#: app/views/handlers/individual_response.py:244
#: app/views/handlers/individual_response.py:245
msgid "We will need their mobile number for this"
msgstr ""

#: app/views/handlers/individual_response.py:249
#: app/views/handlers/individual_response.py:250
msgid "Post"
msgstr ""

#: app/views/handlers/individual_response.py:251
#: app/views/handlers/individual_response.py:252
msgid ""
"We can only send this to an unnamed resident at the registered household "
"address"
msgstr ""

#: app/views/handlers/individual_response.py:351
#: app/views/handlers/individual_response.py:352
msgid "How would you like to answer <em>{person_name_possessive}</em> questions?"
msgstr ""

#: app/views/handlers/individual_response.py:364
#: app/views/handlers/individual_response.py:365
msgid "I would like to request a separate census for them to complete"
msgstr ""

#: app/views/handlers/individual_response.py:370
#: app/views/handlers/individual_response.py:371
msgid "I will ask them to answer their own questions"
msgstr ""

#: app/views/handlers/individual_response.py:374
#: app/views/handlers/individual_response.py:375
msgid "They will need the household access code from the letter we sent you"
msgstr ""

#: app/views/handlers/individual_response.py:380
#: app/views/handlers/individual_response.py:381
msgid "I will answer for {person_name}"
msgstr ""

#: app/views/handlers/individual_response.py:492
#: app/views/handlers/individual_response.py:493
msgid "Do you want to send an individual access code for {person_name} by post?"
msgstr ""

#: app/views/handlers/individual_response.py:498
#: app/views/handlers/individual_response.py:499
msgid ""
"A letter with an individual access code will be sent to your registered "
"household address"
msgstr ""

#: app/views/handlers/individual_response.py:505
#: app/views/handlers/individual_response.py:506
msgid ""
"The letter will be addressed to <strong>Individual Resident</strong> "
"instead of the name provided"
msgstr ""

#: app/views/handlers/individual_response.py:518
#: app/views/handlers/individual_response.py:519
msgid "Yes, send the access code by post"
msgstr ""

#: app/views/handlers/individual_response.py:522
#: app/views/handlers/individual_response.py:523
msgid "No, send it another way"
msgstr ""

#: app/views/handlers/individual_response.py:638
#: app/views/handlers/individual_response.py:651
msgid "Who do you need to request a separate census for?"
msgstr ""

#: app/views/handlers/individual_response.py:688
#: app/views/handlers/individual_response.py:701
msgid "What is <em>{person_name_possessive}</em> mobile number?"
msgstr ""

#: app/views/handlers/individual_response.py:698
#: app/views/handlers/individual_response.py:711
msgid "UK mobile number"
msgstr ""

#: app/views/handlers/individual_response.py:699
#: app/views/handlers/individual_response.py:712
msgid "This will not be stored and only used once to send the access code"
msgstr ""

#: app/views/handlers/individual_response.py:796
#: app/views/handlers/individual_response.py:809
msgid "Is this mobile number correct?"
msgstr ""

#: app/views/handlers/individual_response.py:805
#: app/views/handlers/individual_response.py:818
msgid "Yes, send the text"
msgstr ""

#: app/views/handlers/individual_response.py:809
#: app/views/handlers/individual_response.py:822
msgid "No, I need to change it"
msgstr ""

Expand Down Expand Up @@ -605,7 +605,7 @@ msgstr ""
msgid "Summary"
msgstr ""

#: templates/summary.html:33
#: templates/summary.html:28
msgid "Please review your answers and confirm these are correct"
msgstr ""

Expand Down Expand Up @@ -695,12 +695,21 @@ msgstr ""
msgid "If you have started a survey, your answers have been saved."
msgstr ""

#: templates/errors/500.html:9
#: templates/errors/500.html:9 templates/errors/individual_response.html:9
msgid ""
"<a href='{url}'>Contact us</a> if you need to speak to someone about your"
" survey."
msgstr ""

#: templates/errors/individual_response.html:3
#: templates/errors/individual_response.html:6
msgid "Sorry, there was a problem sending the access code"
msgstr ""

#: templates/errors/individual_response.html:8
msgid "If this problem keeps happening, please contact us for help."
msgstr ""

#: templates/errors/no-cookie.html:3
msgid "Page is not available"
msgstr ""
Expand Down
16 changes: 13 additions & 3 deletions app/views/handlers/individual_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from app.forms.validators import sanitise_mobile_number
from app.helpers.template_helpers import render_template
from app.helpers.url_param_serializer import URLParamSerializer
from app.publisher.exceptions import PublicationFailed
from app.questionnaire.placeholder_renderer import PlaceholderRenderer
from app.questionnaire.router import Router
from app.views.contexts.question import build_question_context
Expand All @@ -24,6 +25,10 @@
GB_NIR_REGION_CODE = "GB-NIR"


class FulfilmentRequestFailedException(Exception):
pass


class IndividualResponseHandler:
_person_name_transform: Mapping = {
"arguments": {
Expand Down Expand Up @@ -141,9 +146,12 @@ def get_context(self):
def _publish_fulfilment_request(self, mobile_number=None):
topic_id = current_app.config["EQ_FULFILMENT_TOPIC_ID"]
fulfilment_request = FulfilmentRequest(self._metadata, mobile_number)
return current_app.eq["publisher"].publish(
topic_id, message=fulfilment_request.payload
)
try:
return current_app.eq["publisher"].publish(
topic_id, message=fulfilment_request.payload
)
except PublicationFailed:
raise FulfilmentRequestFailedException
MebinAbraham marked this conversation as resolved.
Show resolved Hide resolved

def handle_get(self):
individual_section_first_block_id = self._schema.get_first_block_id_for_section(
Expand Down Expand Up @@ -575,6 +583,7 @@ def handle_post(self):
if self.selected_option == self.confirm_option:
self._update_section_status(CompletionStatus.INDIVIDUAL_RESPONSE_REQUESTED)
self._publish_fulfilment_request()

return redirect(
url_for(
"individual_response.individual_response_post_address_confirmation",
Expand Down Expand Up @@ -844,6 +853,7 @@ def handle_post(self):
if self.selected_option == self.confirm_option:
self._update_section_status(CompletionStatus.INDIVIDUAL_RESPONSE_REQUESTED)
self._publish_fulfilment_request(self.mobile_number)

return redirect(
url_for(
"individual_response.individual_response_text_message_confirmation",
Expand Down
10 changes: 10 additions & 0 deletions templates/errors/fulfilment-request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'layouts/_base.html' %}

{% set page_title = _("Sorry, there was a problem sending the access code") %}

{% block main %}
<h1>{{ _("Sorry, there was a problem sending the access code") }}</h1>
<p data-qa="retry">{{ _("You can try to <a href='{retry_url}'>request a new access code again</a>.".format(retry_url = retry_url)) }}</p>
<p >{{ _("If this problem keeps happening, please contact us for help.") }}</p>
JamesGardiner marked this conversation as resolved.
Show resolved Hide resolved
<p>{{ _("<a href='{url}'>Contact us</a> if you need to speak to someone about your survey.").format(url = contact_us_url) }}</p>
{% endblock %}
Loading