2024-09-13 13:52:00 -04:00
|
|
|
<?php
|
|
|
|
|
2024-12-19 15:09:22 -05:00
|
|
|
namespace Socialbox\Exceptions;
|
2024-09-13 13:52:00 -04:00
|
|
|
|
2024-12-19 15:09:22 -05:00
|
|
|
use Exception;
|
|
|
|
use Socialbox\Enums\StandardError;
|
|
|
|
use Socialbox\Objects\RpcError;
|
|
|
|
use Socialbox\Objects\RpcRequest;
|
|
|
|
use Throwable;
|
2024-09-13 13:52:00 -04:00
|
|
|
|
2024-12-19 15:09:22 -05:00
|
|
|
class StandardException extends Exception
|
2024-09-13 13:52:00 -04:00
|
|
|
{
|
2024-12-19 15:09:22 -05:00
|
|
|
/**
|
|
|
|
* Thrown as a standard error, with a message and a code
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param StandardError $code
|
|
|
|
* @param Throwable|null $previous
|
|
|
|
*/
|
|
|
|
public function __construct(string $message, StandardError $code, ?Throwable $previous=null)
|
|
|
|
{
|
|
|
|
parent::__construct($message, $code->value, $previous);
|
|
|
|
}
|
2024-09-13 13:52:00 -04:00
|
|
|
|
2024-12-19 15:09:22 -05:00
|
|
|
public function getStandardError(): StandardError
|
|
|
|
{
|
|
|
|
return StandardError::from($this->code);
|
|
|
|
}
|
2024-09-24 15:01:55 -04:00
|
|
|
|
2024-12-19 15:09:22 -05:00
|
|
|
public function produceError(RpcRequest $request): ?RpcError
|
|
|
|
{
|
|
|
|
return $request->produceError(StandardError::from($this->code), $this->message);
|
|
|
|
}
|
|
|
|
}
|