Refactor RPC framework and enhance error handling.
This commit is contained in:
parent
42ba7013f7
commit
ef3b10b286
10 changed files with 383 additions and 245 deletions
|
@ -1,34 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Exceptions;
|
||||
namespace Socialbox\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Objects\RpcError;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Throwable;
|
||||
use Exception;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Objects\RpcError;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Throwable;
|
||||
|
||||
class StandardException extends Exception
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
class StandardException extends Exception
|
||||
{
|
||||
parent::__construct($message, $code->value, $previous);
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public function getStandardError(): StandardError
|
||||
{
|
||||
return StandardError::from($this->code);
|
||||
}
|
||||
public function getStandardError(): StandardError
|
||||
{
|
||||
return StandardError::from($this->code);
|
||||
}
|
||||
|
||||
public function produceError(RpcRequest $request): ?RpcError
|
||||
{
|
||||
return $request->produceError(StandardError::from($this->code), $this->message);
|
||||
}
|
||||
}
|
||||
public function produceError(RpcRequest $request): ?RpcError
|
||||
{
|
||||
return $request->produceError(StandardError::from($this->code), $this->message);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue