53 lines
1.0 KiB
PHP
53 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace app\api\library;
|
|
|
|
use think\Log;
|
|
|
|
class ApiException extends \RuntimeException
|
|
{
|
|
private $statusCode;
|
|
|
|
private $headers;
|
|
|
|
private $errorCode;
|
|
|
|
public function __construct($message, $code = 0, \Exception $previous = null, array $headers = [], $statusCode = 200)
|
|
{
|
|
if ($code instanceof \Exception) {
|
|
Log::error([
|
|
$message,
|
|
$code->getMessage(),
|
|
$code->getFile(),
|
|
$code->getLine(),
|
|
]);
|
|
$code = 0;
|
|
}
|
|
|
|
if ($code === null) {
|
|
$code = 0;
|
|
}
|
|
|
|
$this->statusCode = $statusCode;
|
|
$this->headers = $headers;
|
|
$this->errorCode = $code;
|
|
|
|
parent::__construct($message, $statusCode, $previous);
|
|
}
|
|
|
|
public function getStatusCode()
|
|
{
|
|
return $this->statusCode;
|
|
}
|
|
|
|
public function getHeaders()
|
|
{
|
|
return $this->headers;
|
|
}
|
|
|
|
public function getErrorCode()
|
|
{
|
|
return $this->errorCode;
|
|
}
|
|
}
|