1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\Exceptions;
- use Exception;
- use Throwable;
- /**
- * 接口的异常
- * Class ApiException
- * @package App\Exceptions
- */
- class ApiException extends Exception
- {
- public function __construct(string $message = "", int $code = 500, Throwable $previous = null)
- {
- parent::__construct($message, $code, $previous);
- }
- /**
- * 将异常渲染到 HTTP 响应中。
- *
- * @param \Illuminate\Http\Request
- * @return void
- */
- public function render($request)
- {
- return response([
- 'code' => $this->getCode(),
- 'status_code' => 400,
- 'message' => $this->getMessage()
- ]);
- }
- }
|