With the JSON error handler you will be able to catch exceptions representing the last occurred JSON error containing the native error codes and error messages of PHP's JSON
package.
Install the latest version with
$ composer require codekandis/json-error-handler
The following example throws a JsonException
with the error code of JsonErrorCodes::SYNTAX
with the message of JsonErrorMessage::SYNTAX
.
json_decode( '{"foobar":}' );
( new JsonErrorHandler() )->handle();
The error codes in JsonErrorCodes
are equal to PHP's native JSON_ERROR
constants. The error messages in JsonErrorMessages
are equal to PHP's error messages of json_last_error_msg()
.