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;
|
namespace D3\DataWizard\Application\Model\ExportRenderer;
|
||||||
|
|
||||||
use D3\DataWizard\Application\Model\Exceptions\RenderException;
|
use D3\DataWizard\Application\Model\Exceptions\RenderException;
|
||||||
|
use JsonException;
|
||||||
|
|
||||||
class Json implements RendererInterface
|
class Json implements RendererInterface
|
||||||
{
|
{
|
||||||
@ -28,12 +29,15 @@ class Json implements RendererInterface
|
|||||||
*/
|
*/
|
||||||
public function getContent($rows, $fieldNames): string
|
public function getContent($rows, $fieldNames): string
|
||||||
{
|
{
|
||||||
$flags = JSON_PRETTY_PRINT;
|
try {
|
||||||
$json = json_encode( $rows, $flags );
|
$flags = JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR;
|
||||||
if ( $json === false ) {
|
$json = json_encode( $rows, $flags );
|
||||||
throw oxNew( RenderException::class, json_last_error_msg(), json_last_error());
|
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
|
public function getFileExtension(): string
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1",
|
"php": ">=7.3",
|
||||||
"oxid-esales/oxideshop-ce": "6.3 - 6.9",
|
"oxid-esales/oxideshop-ce": "6.3 - 6.9",
|
||||||
"league/csv": "^9.0",
|
"league/csv": "^9.0",
|
||||||
"mathieuviossat/arraytotexttable": "^1.0",
|
"mathieuviossat/arraytotexttable": "^1.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user