Refactored translation of exception messages

This commit is contained in:
El RIDO 2025-11-19 09:36:08 +01:00
parent 3e6f1733f9
commit 3a23117ebf
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
24 changed files with 186 additions and 110 deletions

View file

@ -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);
}
}
}