json decoding errors shouldnt' be fatal

This commit is contained in:
Isaac Connor 2020-07-29 16:40:31 -04:00
parent d658479048
commit 4c5a88a822
1 changed files with 12 additions and 7 deletions

View File

@ -2097,18 +2097,23 @@ function isVector(&$array) {
function checkJsonError($value) { function checkJsonError($value) {
if ( function_exists('json_last_error') ) { if ( function_exists('json_last_error') ) {
$value = var_export($value,true); $value = var_export($value, true);
switch( json_last_error() ) { switch ( json_last_error() ) {
case JSON_ERROR_DEPTH : case JSON_ERROR_DEPTH :
ZM\Fatal("Unable to decode JSON string '$value', maximum stack depth exceeded"); ZM\Error("Unable to decode JSON string '$value', maximum stack depth exceeded");
break;
case JSON_ERROR_CTRL_CHAR : case JSON_ERROR_CTRL_CHAR :
ZM\Fatal("Unable to decode JSON string '$value', unexpected control character found"); ZM\Error("Unable to decode JSON string '$value', unexpected control character found");
break;
case JSON_ERROR_STATE_MISMATCH : case JSON_ERROR_STATE_MISMATCH :
ZM\Fatal("Unable to decode JSON string '$value', invalid or malformed JSON"); ZM\Error("Unable to decode JSON string '$value', invalid or malformed JSON");
break;
case JSON_ERROR_SYNTAX : case JSON_ERROR_SYNTAX :
ZM\Fatal("Unable to decode JSON string '$value', syntax error"); ZM\Error("Unable to decode JSON string '$value', syntax error");
break;
default : default :
ZM\Fatal("Unable to decode JSON string '$value', unexpected error ".json_last_error()); ZM\Error("Unable to decode JSON string '$value', unexpected error ".json_last_error());
break;
case JSON_ERROR_NONE: case JSON_ERROR_NONE:
break; break;
} }