ApiException.php 687 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Throwable;
  5. /**
  6. * 接口的异常
  7. * Class ApiException
  8. * @package App\Exceptions
  9. */
  10. class ApiException extends Exception
  11. {
  12. public function __construct(string $message = "", int $code = 500, Throwable $previous = null)
  13. {
  14. parent::__construct($message, $code, $previous);
  15. }
  16. /**
  17. * 将异常渲染到 HTTP 响应中。
  18. *
  19. * @param \Illuminate\Http\Request
  20. * @return void
  21. */
  22. public function render($request)
  23. {
  24. return response([
  25. 'code' => $this->getCode(),
  26. 'status_code' => 400,
  27. 'message' => $this->getMessage()
  28. ]);
  29. }
  30. }