Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0151279

Browse filesBrowse files
committed
minor #32359 [ErrorCatcher] Pretty print JSON formatted errors (javiereguiluz)
This PR was merged into the 4.4 branch. Discussion ---------- [ErrorCatcher] Pretty print JSON formatted errors | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | not needed A long string with JSON contents is not very useful to quickly parse the error contents, so I propose to "pretty print" the JSON errors. Commits ------- ab926d2 [ErrorCatcher] Pretty print JSON formatted errors
2 parents b9b03fe + ab926d2 commit 0151279
Copy full SHA for 0151279

File tree

Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed

‎src/Symfony/Component/ErrorCatcher/ErrorRenderer/JsonErrorRenderer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/ErrorRenderer/JsonErrorRenderer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function render(FlattenException $exception): string
4747
$content['exceptions'] = $exception->toArray();
4848
}
4949

50-
return (string) json_encode($content);
50+
return (string) json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_PRESERVE_ZERO_FRACTION);
5151
}
5252
}

‎src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ class JsonErrorRendererTest extends TestCase
2020
public function testRender()
2121
{
2222
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
23-
$expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":';
23+
$expected = <<<JSON
24+
{
25+
"title": "Internal Server Error",
26+
"status": 500,
27+
"detail": "Foo",
28+
"exceptions": [
29+
{
30+
"message": "Foo",
31+
"class": "RuntimeException",
32+
"trace":
33+
JSON;
2434

2535
$this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception));
2636
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.