Skip to content

Commit fdf01ed

Browse files
committed
Display the 404 and 500 custom error pages
1 parent 89b1cf1 commit fdf01ed

File tree

6 files changed

+102
-5
lines changed

6 files changed

+102
-5
lines changed

composer.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/framework.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ framework:
1919
cookie_samesite: lax
2020

2121
fragments: false
22+
error_controller: Surfnet\StepupSelfService\SelfServiceBundle\Controller\ExceptionController::show
2223
http_method_override: true
2324
php_errors:
2425
log: true

config/packages/monolog.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ monolog:
77
action_level: ERROR
88
passthru_level: NOTICE # this means that all message of level NOTICE or higher are always logged
99
handler: main_stdout
10+
channels: [ "!event" ]
1011
bubble: false # if we handle it, nothing else should
1112
main_stdout:
1213
type: stream
@@ -20,6 +21,7 @@ when@dev:
2021
prod-signaler:
2122
action_level: ERROR
2223
passthru_level: DEBUG # DEV setting: this means that all message of level DEBUG or higher are always logged
24+
channels: [ "!event" ]
2325
bubble: true
2426
main_logfile:
2527
type: stream

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/ExceptionController.php

+37
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller;
2222

23+
use DateTime;
24+
use DateTimeInterface;
25+
use Surfnet\StepupBundle\Exception\Art;
26+
use Symfony\Component\HttpFoundation\Request;
27+
use Symfony\Component\HttpFoundation\Response;
2328
use Throwable;
2429
use Surfnet\StepupBundle\Controller\ExceptionController as BaseExceptionController;
2530
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\MissingRequiredAttributeException;
@@ -48,4 +53,36 @@ protected function getPageTitleAndDescription(Throwable $exception): array
4853

4954
return parent::getPageTitleAndDescription($exception);
5055
}
56+
57+
public function show(Request $request, Throwable $exception): Response
58+
{
59+
$statusCode = $this->getStatusCode($exception);
60+
61+
$template = '@default/bundles/TwigBundle/Exception/error.html.twig';
62+
if ($statusCode == 404) {
63+
$template = '@default/bundles/TwigBundle/Exception/error404.html.twig';
64+
}
65+
66+
$response = new Response('', $statusCode);
67+
68+
$timestamp = (new DateTime)->format(DateTimeInterface::ATOM);
69+
$hostname = $request->getHost();
70+
$requestId = $this->requestId;
71+
$errorCode = Art::forException($exception);
72+
$userAgent = $request->headers->get('User-Agent');
73+
$ipAddress = $request->getClientIp();
74+
75+
return $this->render(
76+
$template,
77+
[
78+
'timestamp' => $timestamp,
79+
'hostname' => $hostname,
80+
'request_id' => $requestId->get(),
81+
'error_code' => $errorCode,
82+
'user_agent' => $userAgent,
83+
'ip_address' => $ipAddress,
84+
] + $this->getPageTitleAndDescription($exception),
85+
$response
86+
);
87+
}
5188
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{% extends 'base.html.twig' %}
2+
3+
{% block title %}{{ 'Error - ' ~ title }}{% endblock %}
4+
5+
{% block content %}
6+
<p class="error-description">{{ description }}</p>
7+
8+
<table class="table table-bordered">
9+
<tr>
10+
<th>{{ 'stepup.error.timestamp'|trans }}</th>
11+
<td>{{ timestamp }}</td>
12+
</tr>
13+
<tr>
14+
<th>{{ 'stepup.error.hostname'|trans }}</th>
15+
<td>{{ hostname }}</td>
16+
</tr>
17+
<tr>
18+
<th>{{ 'stepup.error.request_id'|trans }}</th>
19+
<td>{{ request_id }}</td>
20+
</tr>
21+
<tr>
22+
<th>{{ 'stepup.error.error_code'|trans }}</th>
23+
<td>{{ error_code }}</td>
24+
</tr>
25+
{% if user_agent %}
26+
<tr>
27+
<th>{{ 'stepup.error.user_agent'|trans }}</th>
28+
<td>{{ user_agent }}</td>
29+
</tr>
30+
{% endif %}
31+
<tr>
32+
<th>{{ 'stepup.error.ip_address'|trans }}</th>
33+
<td>{{ ip_address }}</td>
34+
</tr>
35+
</table>
36+
37+
<p class="error-description">{{ 'stepup.error.support_page.text'|trans({'%support_url%': global_view_parameters.supportUrl })|raw }}</p>
38+
39+
{# For now the back button is not shown on the error page until a more intelligent solution is thought of #}
40+
{% block back_button %}{% endblock %}
41+
42+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends 'base.html.twig' %}
2+
3+
{% block title %}{{ 'stepup.error.page_not_found.title'|trans }}{% endblock %}
4+
5+
{% block content %}
6+
<p>{{ 'stepup.error.page_not_found.text'|trans }}</p>
7+
8+
<hr>
9+
10+
<p>{{ 'stepup.error.support_page.text'|trans({'%support_url%': global_view_parameters.supportUrl })|raw }}</p>
11+
12+
{# For now the back button is not shown on the error page until a more intelligent solution is thought of #}
13+
{% block back_button %}{% endblock %}
14+
15+
{% endblock %}

0 commit comments

Comments
 (0)