Skip to content
Permalink
Browse files

minor #32359 [ErrorCatcher] Pretty print JSON formatted errors (javie…

…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 0151279cfe3cd0511fc29da22af2e993705abd88
@@ -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);
}
}
@@ -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));
}

0 comments on commit 0151279

Please sign in to comment.
You can’t perform that action at this time.