-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* It's free open-source software released under the MIT License. | ||
* | ||
* @author Anatoly Fenric <anatoly@fenric.ru> | ||
* @copyright Copyright (c) 2018, Anatoly Fenric | ||
* @license https://github.com/sunrise-php/http-message/blob/master/LICENSE | ||
* @link https://github.com/sunrise-php/http-message | ||
*/ | ||
|
||
namespace Sunrise\Http\Message\Exception; | ||
|
||
/** | ||
* Import classes | ||
*/ | ||
use RuntimeException; | ||
|
||
/** | ||
* Import functions | ||
*/ | ||
use function json_last_error; | ||
use function json_last_error_msg; | ||
|
||
/** | ||
* Import constants | ||
*/ | ||
use const JSON_ERROR_NONE; | ||
|
||
/** | ||
* JsonException | ||
*/ | ||
class JsonException extends RuntimeException | ||
{ | ||
|
||
/** | ||
* @return void | ||
* | ||
* @throws self | ||
*/ | ||
public static function assert() : void | ||
{ | ||
$code = json_last_error(); | ||
|
||
if (JSON_ERROR_NONE === $code) { | ||
return; | ||
} | ||
|
||
throw new self(json_last_error_msg(), $code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters