[ErrorCatcher] Pretty print JSON formatted errors

This commit is contained in:
Javier Eguiluz 2019-07-04 10:10:13 +02:00 committed by Yonel Ceruto
parent e3927b6294
commit ab926d2065
2 changed files with 12 additions and 2 deletions

View File

@ -47,6 +47,6 @@ class JsonErrorRenderer implements ErrorRendererInterface
$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);
}
}

View File

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