handle JSON exception
This commit is contained in:
parent
e134a4c14a
commit
5251490b74
@ -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
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user