Improved InvalidRpcArgumentException handling
This commit is contained in:
parent
55137a93f2
commit
0ed6a36d50
11 changed files with 43 additions and 25 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Socialbox\Exceptions\Standard;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Enums\StandardError;
|
||||
|
||||
class InvalidRpcArgumentException extends StandardRpcException
|
||||
|
@ -10,10 +12,22 @@
|
|||
* Thrown when a required parameter is missing
|
||||
*
|
||||
* @param string $parameterName The name of the parameter that is missing
|
||||
* @param string $reason The reason why the parameter is invalid
|
||||
* @param string|Exception|null $reason The reason why the parameter is invalid can be a string or an exception or null
|
||||
*/
|
||||
public function __construct(string $parameterName, string $reason)
|
||||
public function __construct(string $parameterName, null|string|Exception $reason=null)
|
||||
{
|
||||
if(is_null($reason))
|
||||
{
|
||||
parent::__construct(sprintf('Invalid parameter %s', $parameterName), StandardError::RPC_INVALID_ARGUMENTS);
|
||||
return;
|
||||
}
|
||||
|
||||
if($reason instanceof InvalidArgumentException)
|
||||
{
|
||||
parent::__construct(sprintf('Invalid parameter %s: %s', $parameterName, $reason->getMessage()), StandardError::RPC_INVALID_ARGUMENTS, $reason);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct(sprintf('Invalid parameter %s: %s', $parameterName, $reason), StandardError::RPC_INVALID_ARGUMENTS);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue