E57C removed HttpException base class, refactored FlattenException class · symfony/symfony@55bed30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55bed30

Browse files
committed
removed HttpException base class, refactored FlattenException class
1 parent 23fbd87 commit 55bed30

File tree

14 files changed

+28
-68
lines changed

14 files changed

+28
-68
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Component\DependencyInjection\ContainerAware;
66
use Symfony\Component\HttpKernel\Exception\FlattenException;
77
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
8+
use Symfony\Component\HttpFoundation\Response;
89

910
/*
1011
* This file is part of the Symfony framework.
@@ -40,9 +41,7 @@ public function exceptionAction(FlattenException $exception, DebugLoggerInterfac
4041
$currentContent .= ob_get_clean();
4142
}
4243

43-
if ('Symfony\Component\Security\Exception\AccessDeniedException' === $exception->getClass()) {
44-
$exception->setStatusCode($exception->getCode());
45-
}
44+
$code = $this->getStatusCode($exception);
4645

4746
$template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
4847
if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
@@ -58,14 +57,28 @@ public function exceptionAction(FlattenException $exception, DebugLoggerInterfac
5857
$response = $templating->renderResponse(
5958
$template,
6059
array(
60+
'status_code' => $code,
61+
'status_text' => Response::$statusTexts[$code],
6162
'exception' => $exception,
6263
'logger' => $logger,
6364
'currentContent' => $currentContent,
6465
)
6566
);
6667

67-
$response->setStatusCode($exception->getStatusCode());
68+
$response->setStatusCode($code);
6869

6970
return $response;
7071
}
72+
73+
protected function FF8 getStatusCode(FlattenException $exception)
74+
{
75+
switch ($exception->getClass()) {
76+
case 'Symfony\Component\Security\Exception\AccessDeniedException':
77+
return 403;
78+
case 'Symfony\Component\HttpKernel\Exception\HttpNotFoundException':
79+
return 404;
80+
default:
81+
return 500;
82+
}
83+
}
7184
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/*
2-
{{ exception.statuscode }} {{ exception.statustext }}
2+
{{ status_code }} {{ status_text }}
33

44
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/*
2-
{{ exception.statuscode }} {{ exception.statustext }}
2+
{{ status_code }} {{ status_text }}
33

44
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ ['error': ['code': exception.statuscode, 'message': exception.statustext]]|json_encode }}
1+
{{ ['error': ['code': status_code, 'message': status_text]]|json_encode }}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body>
77
<h1>Oops! An Error Occurred</h1>
8-
<h2>The server returned a "{{ exception.statuscode }} {{ exception.statustext }}".</h2>
8+
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
99

1010
<div>
1111
Something is broken. Please e-mail us at [email] and let us know

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Oops! An Error Occurred
22
=======================
33

4-
The server returned a "{{ exception.statuscode }} {{ exception.statustext }}".
4+
The server returned a "{{ status_code }} {{ status_text }}".
55

66
Please e-mail us at [email] and let us know what you were doing when this
77
error occurred. We will fix it as soon as possible. Sorry for any
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="{{ _charset }}" ?>
22

3-
<error code="{{ exception.statuscode }}" message="{{ exception.statustext }}" />
3+
<error code="{{ status_code }}" message="{{ status_text }}" />

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</div>
66
<div style="float: left; width: 600px">
77
<h1>{{ exception.message|replace(["\n": '<br />'])|format_file_from_text }}</h1>
8-
<h2><strong>{{ exception.statuscode }}</strong> {{ exception.statustext }} - {{ exception.class|abbr_class }}</h2>
8+
<h2><strong>{{ status_code }}</strong> {{ status_text }} - {{ exception.class|abbr_class }}</h2>
99

1010
{% set previous_count = exception.previouses|length %}
1111
{% if previous_count %}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[exception] {{ exception.statuscode ~ ' | ' ~ exception.statustext ~ ' | ' ~ exception.class }}
1+
[exception] {{ status_code ~ ' | ' ~ status_text ~ ' | ' ~ exception.class }}
22
[message] {{ exception.message }}
33
{% for i, e in exception.toarray %}
44
[{{ i + 1 }}] {{ e.class }}: {{ e.message }}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="{{ _charset }}" ?>
22

3-
<error code="{{ exception.statuscode }}" message="{{ exception.statustext }}">
3+
<error code="{{ status_code }}" message="{{ status_text }}">
44
{% for e in exception.toarray %}
55
<exception class="{{ e.class }}" message="{{ e.message }}">
66
{% include 'FrameworkBundle:Exception:traces.twig' with ['exception': e] only %}

0 commit comments

Comments
 (0)
0