-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kim Pepper <[email protected]>
- Loading branch information
Showing
21 changed files
with
147 additions
and
85 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
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
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
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSearch\Exception; | ||
|
||
use OpenSearch\Common\Exceptions\OpenSearchException; | ||
|
||
/** | ||
* An exception thrown when invalid arguments are passed to a method. | ||
* | ||
* @phpstan-ignore class.implementsDeprecatedInterface | ||
*/ | ||
class BadMethodCallException extends \BadMethodCallException implements OpenSearchException | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSearch\Exception; | ||
|
||
use OpenSearch\Common\Exceptions\OpenSearchException; | ||
|
||
/** | ||
* Provides an exception for JSON errors. | ||
* | ||
* @phpstan-ignore class.implementsDeprecatedInterface | ||
*/ | ||
class JsonException extends \JsonException implements OpenSearchException | ||
{ | ||
private readonly mixed $input; | ||
|
||
private readonly mixed $result; | ||
|
||
public function __construct(int $code, mixed $input, mixed $result, ?\Throwable $previous = null) | ||
{ | ||
parent::__construct($this->getErrorMessage($code), $code, $previous); | ||
$this->input = $input; | ||
$this->result = $result; | ||
} | ||
|
||
public function getInput(): mixed | ||
{ | ||
return $this->input; | ||
} | ||
|
||
public function getResult(): mixed | ||
{ | ||
return $this->result; | ||
} | ||
|
||
/** | ||
* Gets the JSON error message for the given error code. | ||
*/ | ||
private function getErrorMessage(int $code): string | ||
{ | ||
return match ($code) { | ||
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', | ||
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', | ||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', | ||
JSON_ERROR_SYNTAX => 'Syntax error', | ||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', | ||
JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', | ||
JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', | ||
JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given', | ||
|
||
// JSON_ERROR_* constant values that are available on PHP >= 7.0 | ||
9 => 'Decoding of value would result in invalid PHP property name', //JSON_ERROR_INVALID_PROPERTY_NAME | ||
10 => 'Attempted to decode nonexistent UTF-16 code-point',//JSON_ERROR_UTF16 | ||
default => throw new \InvalidArgumentException("Encountered unknown JSON error code: [{$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSearch\Exception; | ||
|
||
use OpenSearch\Common\Exceptions\OpenSearchException; | ||
|
||
/** | ||
* An exception thrown when a runtime error occurs. | ||
* | ||
* @phpstan-ignore class.implementsDeprecatedInterface | ||
*/ | ||
class RuntimeException extends \RuntimeException implements OpenSearchException | ||
{ | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSearch\Exception; | ||
|
||
use OpenSearch\Common\Exceptions\OpenSearchException; | ||
|
||
/** | ||
* An exception thrown when invalid arguments are passed to a method. | ||
* | ||
* @phpstan-ignore class.implementsDeprecatedInterface | ||
*/ | ||
class UnexpectedValueException extends \UnexpectedValueException implements OpenSearchException | ||
{ | ||
} |
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
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
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
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
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
Oops, something went wrong.