Init commit.
This commit is contained in:
commit
c9cce3cd39
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.idea
|
||||||
|
|
||||||
|
vendor
|
||||||
|
|
||||||
|
*.log
|
13
composer.json
Normal file
13
composer.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"name": "paidian/tool-kit",
|
||||||
|
"type": "metapackage",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Amast",
|
||||||
|
"email": "17783854897@163.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"illuminate/http": "^6.4"
|
||||||
|
}
|
||||||
|
}
|
1562
composer.lock
generated
Normal file
1562
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
56
src/Exceptions/ApiException.php
Normal file
56
src/Exceptions/ApiException.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Throwable;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class ApiException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 返回到接口的验证码
|
||||||
|
* @var int $response_code
|
||||||
|
*/
|
||||||
|
protected $response_code = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 static function formException(Exception $e, $response_code = 400000)
|
||||||
|
{
|
||||||
|
return new ApiException($e->getMessage(), $response_code, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getResponseCode()
|
||||||
|
{
|
||||||
|
return $this->response_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function render(): JsonResponse
|
||||||
|
{
|
||||||
|
return new JsonResponse([
|
||||||
|
'message' => $this->getMessage(),
|
||||||
|
'code' => $this->getResponseCode(),
|
||||||
|
'data' => new \stdClass(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user