Skip to content

Commit

Permalink
fixup! Use native exception for json functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lcobucci committed Jun 21, 2019
1 parent 8bbcf89 commit da4fb4d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Formatter/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use const JSON_HEX_TAG;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use function assert;
use function is_string;
use function json_encode;
use function sprintf;

Expand All @@ -35,7 +37,10 @@ public function __construct(int $flags = self::DEFAULT_FLAGS)
public function format($content, array $attributes = []): string
{
try {
return json_encode($content, $this->flags | JSON_THROW_ON_ERROR);
$content = json_encode($content, $this->flags | JSON_THROW_ON_ERROR);
assert(is_string($content));

return $content;
} catch (Throwable $exception) {
throw new ContentCouldNotBeFormatted(
sprintf('An exception was thrown during JSON formatting: %s', $exception->getMessage()),
Expand Down

0 comments on commit da4fb4d

Please sign in to comment.