mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 04:58:15 +01:00
Turn abstract exception into an interface
This commit is contained in:
parent
4ae685988f
commit
8b39422123
@ -2,16 +2,12 @@
|
||||
|
||||
namespace Cerbero\JsonParser\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Any exception thrown by JSON Parser.
|
||||
*
|
||||
*/
|
||||
abstract class JsonParserException extends Exception
|
||||
interface JsonParserException extends Throwable
|
||||
{
|
||||
public const SOURCE_UNSUPPORTED = 0;
|
||||
public const SOURCE_GUZZLE = 1;
|
||||
|
||||
public const POINTER_INVALID = 0;
|
||||
}
|
||||
|
@ -2,12 +2,16 @@
|
||||
|
||||
namespace Cerbero\JsonParser\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* The exception thrown when a pointer-related error occurs.
|
||||
*
|
||||
*/
|
||||
final class PointerException extends JsonParserException
|
||||
final class PointerException extends Exception implements JsonParserException
|
||||
{
|
||||
public const CODE_INVALID = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the exception when the given pointer is invalid
|
||||
*
|
||||
@ -16,6 +20,6 @@ final class PointerException extends JsonParserException
|
||||
*/
|
||||
public static function invalid(string $pointer): static
|
||||
{
|
||||
return new static("The string [$pointer] is not a valid JSON pointer", static::POINTER_INVALID);
|
||||
return new static("The string [$pointer] is not a valid JSON pointer", static::CODE_INVALID);
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,17 @@
|
||||
|
||||
namespace Cerbero\JsonParser\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* The exception thrown when a source-related error occurs.
|
||||
*
|
||||
*/
|
||||
final class SourceException extends JsonParserException
|
||||
final class SourceException extends Exception implements JsonParserException
|
||||
{
|
||||
public const CODE_UNSUPPORTED = 0;
|
||||
public const CODE_GUZZLE = 1;
|
||||
|
||||
/**
|
||||
* Retrieve the exception when a JSON source is not supported
|
||||
*
|
||||
@ -15,7 +20,7 @@ final class SourceException extends JsonParserException
|
||||
*/
|
||||
public static function unsupported(): static
|
||||
{
|
||||
return new static('Unable to load JSON from the provided source', static::SOURCE_UNSUPPORTED);
|
||||
return new static('Unable to load JSON from the provided source', static::CODE_UNSUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,6 +30,6 @@ final class SourceException extends JsonParserException
|
||||
*/
|
||||
public static function requireGuzzle(): static
|
||||
{
|
||||
return new static('Guzzle is required to load JSON from endpoints', static::SOURCE_GUZZLE);
|
||||
return new static('Guzzle is required to load JSON from endpoints', static::CODE_GUZZLE);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user