Skip to content

Commit

Permalink
minor #32359 [ErrorCatcher] Pretty print JSON formatted errors (javie…
Browse files Browse the repository at this point in the history
…reguiluz)

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
  • Loading branch information
yceruto committed Jul 4, 2019
2 parents b9b03fe + ab926d2 commit 0151279
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -47,6 +47,6 @@ public function render(FlattenException $exception): string
$content['exceptions'] = $exception->toArray();
}

return (string) json_encode($content);
return (string) json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_LINE_TERMINATORS | JSON_PRESERVE_ZERO_FRACTION);
}
}
Expand Up @@ -20,7 +20,17 @@ class JsonErrorRendererTest extends TestCase
public function testRender()
{
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
$expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":';
$expected = <<<JSON
{
"title": "Internal Server Error",
"status": 500,
"detail": "Foo",
"exceptions": [
{
"message": "Foo",
"class": "RuntimeException",
"trace":
JSON;

$this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception));
}
Expand Down

0 comments on commit 0151279

Please sign in to comment.