From 5251490b744f8264062b9f89c4078c5895113ad5 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 10 Nov 2021 13:52:26 +0100 Subject: [PATCH] handle JSON exception --- Application/Model/ExportRenderer/Json.php | 14 +++++++++----- composer.json | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Application/Model/ExportRenderer/Json.php b/Application/Model/ExportRenderer/Json.php index 8677b62..283dd31 100644 --- a/Application/Model/ExportRenderer/Json.php +++ b/Application/Model/ExportRenderer/Json.php @@ -16,6 +16,7 @@ declare(strict_types=1); namespace D3\DataWizard\Application\Model\ExportRenderer; use D3\DataWizard\Application\Model\Exceptions\RenderException; +use JsonException; class Json implements RendererInterface { @@ -28,12 +29,15 @@ class Json implements RendererInterface */ public function getContent($rows, $fieldNames): string { - $flags = JSON_PRETTY_PRINT; - $json = json_encode( $rows, $flags ); - if ( $json === false ) { - throw oxNew( RenderException::class, json_last_error_msg(), json_last_error()); + try { + $flags = JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR; + $json = json_encode( $rows, $flags ); + return $json; + } catch ( JsonException $e) { + /** @var RenderException $newException */ + $newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e ); + throw $newException; } - return $json; } public function getFileExtension(): string diff --git a/composer.json b/composer.json index 85cf308..47d452a 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "GPL-3.0-or-later" ], "require": { - "php": ">=7.1", + "php": ">=7.3", "oxid-esales/oxideshop-ce": "6.3 - 6.9", "league/csv": "^9.0", "mathieuviossat/arraytotexttable": "^1.0",