BasketSnapshot: simplify error handling

We have no IcingaObject here, they're all stdClass instances
This commit is contained in:
Thomas Gelf 2022-10-25 11:10:05 +02:00
parent 470137b5c2
commit ad5dfc8496

View File

@ -424,22 +424,18 @@ class BasketSnapshot extends DbObject
return JsonString::encode($this->objects, JSON_PRETTY_PRINT); return JsonString::encode($this->objects, JSON_PRETTY_PRINT);
} catch (JsonEncodeException $e) { } catch (JsonEncodeException $e) {
foreach ($this->objects as $type => $objects) { foreach ($this->objects as $type => $objects) {
foreach ($objects as $key => $object) { foreach ($objects as $object) {
try { try {
JsonString::encode($object); JsonString::encode($object);
} catch (JsonEncodeException $singleError) { } catch (JsonEncodeException $singleError) {
if ($object instanceof IcingaObject) { $dump = var_export($object, 1);
$name = $object->getObjectName(); if (function_exists('iconv')) {
} else { $dump = iconv('UTF-8', 'UTF-8//IGNORE', $dump);
$name = var_export($object, 1);
if (function_exists('iconv')) {
$name = iconv('UTF-8', 'UTF-8//IGNORE', $name);
}
} }
throw new JsonEncodeException(sprintf( throw new JsonEncodeException(sprintf(
'Failed to encode object ot type "%s": "%s", %s', 'Failed to encode object ot type "%s": %s, %s',
$type, $type,
$name, $dump,
$singleError->getMessage() $singleError->getMessage()
), $singleError->getCode()); ), $singleError->getCode());
} }