mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-01-23 02:35:23 +00:00
Refactored translation of exception messages
This commit is contained in:
parent
3e6f1733f9
commit
3a23117ebf
24 changed files with 186 additions and 110 deletions
21
lib/Json.php
21
lib/Json.php
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace PrivateBin;
|
||||
|
||||
use Exception;
|
||||
use PrivateBin\Exception\JsonException;
|
||||
|
||||
/**
|
||||
* Json
|
||||
|
|
@ -26,7 +26,7 @@ class Json
|
|||
* @access public
|
||||
* @static
|
||||
* @param mixed $input
|
||||
* @throws Exception
|
||||
* @throws JsonException
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(&$input)
|
||||
|
|
@ -42,7 +42,7 @@ class Json
|
|||
* @access public
|
||||
* @static
|
||||
* @param string $input
|
||||
* @throws Exception
|
||||
* @throws JsonException
|
||||
* @return mixed
|
||||
*/
|
||||
public static function decode(&$input)
|
||||
|
|
@ -57,21 +57,14 @@ class Json
|
|||
*
|
||||
* @access private
|
||||
* @static
|
||||
* @throws Exception
|
||||
* @throws JsonException
|
||||
* @return void
|
||||
*/
|
||||
private static function _detectError()
|
||||
{
|
||||
$errorCode = json_last_error();
|
||||
if ($errorCode === JSON_ERROR_NONE) {
|
||||
return;
|
||||
if ($errorCode !== JSON_ERROR_NONE) {
|
||||
throw new JsonException($errorCode);
|
||||
}
|
||||
|
||||
$message = 'A JSON error occurred';
|
||||
if (function_exists('json_last_error_msg')) {
|
||||
$message .= ': ' . json_last_error_msg();
|
||||
}
|
||||
$message .= ' (' . $errorCode . ')';
|
||||
throw new Exception($message, 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue