Refacting ApiException response code.

This commit is contained in:
Amast 2019-10-31 17:23:54 +08:00
parent 133d8ecfe0
commit 3b147cd3be
3 changed files with 12 additions and 16 deletions

View File

@ -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);
}
/**

View File

@ -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;
}

View File

@ -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);
}
}