8000 bug #27722 Redesign the Debug error page in prod (javiereguiluz) · symfony/symfony@5971e2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5971e2d

Browse files
committed
bug #27722 Redesign the Debug error page in prod (javiereguiluz)
This PR was merged into the 3.4 branch. Discussion ---------- Redesign the Debug error page in prod | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22964 | License | MIT | Doc PR | - In `debug` mode, things are unchanged and the page looks like this: ![error-debug](https://user-images.githubusercontent.com/73419/41900161-5a2dfc3a-792e-11e8-8806-6333cce8cee9.png) In `non-debug` mode, all Symfony-related things are removed and we use the same minimal design as the default `prod` error pages (see #27699): ![error-no-debug](https://user-images.githubusercontent.com/73419/41900218-798fda6c-792e-11e8-8b8e-22415ab810ac.png) Commits ------- 7b9b1b9 Redesign the Debug error page in prod
2 parents 3d8490e + 7b9b1b9 commit 5971e2d

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -208,48 +208,54 @@ public function getContent(FlattenException $exception)
208208
$title = 'Whoops, looks like something went wrong.';
209209
}
210210

211+
if (!$this->debug) {
212+
return <<<EOF
213+
<div class="container">
214+
<h1>$title</h1>
215+
</div>
216+
EOF;
217+
}
218+
211219
$content = '';
212-
if ($this->debug) {
213-
try {
214-
$count = count($exception->getAllPrevious());
215-
$total = $count + 1;
216-
foreach ($exception->toArray() as $position => $e) {
217-
$ind = $count - $position + 1;
218-
$class = $this->formatClass($e['class']);
219-
$message = nl2br($this->escapeHtml($e['message']));
220-
$content .= sprintf(<<<'EOF'
221-
<div class="trace trace-as-html">
222-
<table class="trace-details">
223-
<thead class="trace-head"><tr><th>
224-
<h3 class="trace-class">
225-
<span class="text-muted">(%d/%d)</span>
226-
<span class="exception_title">%s</span>
227-
</h3>
228-
<p class="break-long-words trace-message">%s</p>
229-
</th></tr></thead>
230-
<tbody>
220+
try {
221+
$count = count($exception->getAllPrevious());
222+
$total = $count + 1;
223+
foreach ($exception->toArray() as $position => $e) {
224+
$ind = $count - $position + 1;
225+
$class = $this->formatClass($e['class']);
226+
$message = nl2br($this->escapeHtml($e['message']));
227+
$content .= sprintf(<<<'EOF'
228+
<div class="trace trace-as-html">
229+
<table class="trace-details">
230+
<thead class="trace-head"><tr><th>
231+
<h3 class="trace-class">
232+
<span class="text-muted">(%d/%d)</span>
233+
<span class="exception_title">%s</span>
234+
</h3>
235+
<p class="break-long-words trace-message">%s</p>
236+
</th></tr></thead>
237+
<tbody>
231238
EOF
232-
, $ind, $total, $class, $message);
233-
foreach ($e['trace'] as $trace) {
234-
$content .= '<tr><td>';
235-
if ($trace['function']) {
236-
$content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
237-
}
238-
if (isset($trace['file']) && isset($trace['line'])) {
239-
$content .= $this->formatPath($trace['file'], $trace['line']);
240-
}
241-
$content .= "</td></tr>\n";
239+
, $ind, $total, $class, $message);
240+
foreach ($e['trace'] as $trace) {
241+
$content .= '<tr><td>';
242+
if ($trace['function']) {
243+
$content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
242244
}
243-
244-
$content .= "</tbody>\n</table>\n</div>\n";
245-
}
246-
} catch (\Exception $e) {
247-
// something nasty happened and we cannot throw an exception anymore
248-
if ($this->debug) {
249-
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
250-
} else {
251-
$title = 'Whoops, looks like something went wrong.';
245+
if (isset($trace['file']) && isset($trace['line'])) {
246+
$content .= $this->formatPath($trace['file'], $trace['line']);
247+
}
248+
$content .= "</td></tr>\n";
252249
}
250+
251+
$content .= "</tbody>\n</table>\n</div>\n";
252+
}
253+
} catch (\Exception $e) {
254+
// something nasty happened and we cannot throw an exception anymore
255+
if ($this->debug) {
256+
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
257+
} else {
258+
$title = 'Whoops, looks like something went wrong.';
253259
}
254260
}
255261

@@ -278,6 +284,14 @@ public function getContent(FlattenException $exception)
278284
*/
279285
public function getStylesheet(FlattenException $exception)
280286
{
287+
if (!$this->debug) {
288+
return <<<'EOF'
289+
body { background-color: #fff; color: #222; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; }
290+
.container { margin: 30px; max-width: 600px; }
291+
h1 { color: #dc3545; font-size: 24px; }
292+
EOF;
293+
}
294+
281295
return <<<'EOF'
282296
body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; }
283297

0 commit comments

Comments
 (0)
0