From 3b147cd3befd8cace80633f69030e08721b743de Mon Sep 17 00:00:00 2001 From: Amast <17783854897@163.com> Date: Thu, 31 Oct 2019 17:23:54 +0800 Subject: [PATCH] Refacting ApiException response code. --- src/Exceptions/ApiException.php | 17 ++++++----------- src/Exceptions/ApiInvalidParamException.php | 5 +---- src/Exceptions/ApiSystemException.php | 6 +++++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 1d5d65b..c2d2d89 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -12,26 +12,21 @@ class ApiException extends Exception * 返回到接口的验证码 * @var int $response_code */ - protected $response_code = 0; + protected $response_code = 400000; /** * ApiException constructor. * @param string $message - * @param int $response_code * @param Throwable|null $previous */ - public function __construct( - $message, - $response_code = 400000, - Throwable $previous = null - ) { - parent::__construct($message, 0, $previous); - $this->response_code = $response_code; + public function __construct(string $message, Throwable $previous = null) + { + parent::__construct($message, $previous); } - public static function formException(Exception $e, $response_code = 400000) + public static function fromException(Exception $e) { - return new ApiException($e->getMessage(), $response_code, $e); + return new ApiException($e->getMessage(), $e); } /** diff --git a/src/Exceptions/ApiInvalidParamException.php b/src/Exceptions/ApiInvalidParamException.php index 2e96820..16282f2 100644 --- a/src/Exceptions/ApiInvalidParamException.php +++ b/src/Exceptions/ApiInvalidParamException.php @@ -4,8 +4,5 @@ namespace PdToolKit\Exceptions; class ApiInvalidParamException extends ApiException { - public function __construct($message, Throwable $previous = null) - { - parent::__construct($message, 400400, $previous); - } + protected $response_code = 400400; } \ No newline at end of file diff --git a/src/Exceptions/ApiSystemException.php b/src/Exceptions/ApiSystemException.php index 7e21c12..7853af9 100644 --- a/src/Exceptions/ApiSystemException.php +++ b/src/Exceptions/ApiSystemException.php @@ -2,10 +2,14 @@ namespace PdToolKit\Exceptions; +use Throwable; + class ApiSystemException extends ApiException { + protected $response_code = 400000; + public function __construct($message = "网络波动,稍后再试", Throwable $previous = null) { - parent::__construct($message, 400000, $previous); + parent::__construct($message, $previous); } } \ No newline at end of file