codekandis / json-error-handler
`codekandis/json-error-handler` is a library to handle JSON errors in an object oriented way.
Installs: 704
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/codekandis/json-error-handler
Requires
- php: ^7.4
- codekandis/constants-classes-translator: ^1
- codekandis/phlags: ^3
Requires (Dev)
- codekandis/phpunit: ^3
- roave/security-advisories: dev-master
README
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.
Index
Installation
Install the latest version with
$ composer require codekandis/json-error-handler
How to use
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().