mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
PropertyModifierJsonDecode: fail on error...
...and give some details fixes #13733
This commit is contained in:
parent
8fa9bafd6e
commit
2ef36899e9
@ -36,7 +36,7 @@ class PropertyModifierJsonDecode extends PropertyModifierHook
|
|||||||
}
|
}
|
||||||
|
|
||||||
$decoded = @json_decode($value);
|
$decoded = @json_decode($value);
|
||||||
if ($decoded === null && JSON_ERROR_NONE === json_last_error()) {
|
if ($decoded === null && JSON_ERROR_NONE !== json_last_error()) {
|
||||||
switch ($this->getSetting('on_failure')) {
|
switch ($this->getSetting('on_failure')) {
|
||||||
case 'null':
|
case 'null':
|
||||||
return null;
|
return null;
|
||||||
@ -45,7 +45,8 @@ class PropertyModifierJsonDecode extends PropertyModifierHook
|
|||||||
case 'fail':
|
case 'fail':
|
||||||
default:
|
default:
|
||||||
throw new InvalidPropertyException(
|
throw new InvalidPropertyException(
|
||||||
'JSON decoding failed for %s',
|
'JSON decoding failed with "%s" for %s',
|
||||||
|
$this->getLastJsonError(),
|
||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -53,4 +54,23 @@ class PropertyModifierJsonDecode extends PropertyModifierHook
|
|||||||
|
|
||||||
return $decoded;
|
return $decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: just return json_last_error_msg() for PHP >= 5.5.0
|
||||||
|
protected function getLastJsonError()
|
||||||
|
{
|
||||||
|
switch (json_last_error()) {
|
||||||
|
case JSON_ERROR_DEPTH:
|
||||||
|
return 'The maximum stack depth has been exceeded';
|
||||||
|
case JSON_ERROR_CTRL_CHAR:
|
||||||
|
return 'Control character error, possibly incorrectly encoded';
|
||||||
|
case JSON_ERROR_STATE_MISMATCH:
|
||||||
|
return 'Invalid or malformed JSON';
|
||||||
|
case JSON_ERROR_SYNTAX:
|
||||||
|
return 'Syntax error';
|
||||||
|
case JSON_ERROR_UTF8:
|
||||||
|
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||||
|
default:
|
||||||
|
return 'An error occured when parsing a JSON string';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user