Record error when JSON encoding fails in JSONDisplayHandler

This commit is contained in:
Kijin Sung 2024-08-24 13:16:30 +09:00
parent ce11578617
commit f0c27773c4

View file

@ -15,7 +15,16 @@ class JSONDisplayHandler
$variables['message'] = $oModule->getMessage();
self::_convertCompat($variables, Context::getRequestMethod());
return json_encode($variables) . "\n";
$result = json_encode($variables) . "\n";
if (json_last_error() != \JSON_ERROR_NONE)
{
trigger_error('JSON encoding error: ' . json_last_error_msg(), E_USER_WARNING);
return json_encode([
'error' => -1,
'message' => 'JSON encoding error',
]) . "\n";
}
return $result;
}
/**