Init commit.

This commit is contained in:
Amast 2019-10-30 17:57:26 +08:00
commit c9cce3cd39
4 changed files with 1636 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.idea
vendor
*.log

13
composer.json Normal file
View 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

File diff suppressed because it is too large Load Diff

View 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(),
]);
}
}