handle JSON exception

Cette révision appartient à :
Daniel Seifert 2021-11-10 13:52:26 +01:00
Parent e134a4c14a
révision 5251490b74
Signé par: DanielS
ID de la clé GPG: 8A7C4C6ED1915C6F
2 fichiers modifiés avec 10 ajouts et 6 suppressions

Voir le fichier

@ -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;
try {
$flags = JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR;
$json = json_encode( $rows, $flags );
if ( $json === false ) {
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;
}
}
public function getFileExtension(): string

Voir le fichier

@ -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",