AlertException.php 711 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Throwable;
  5. /**
  6. * 非200正常返回的情况前端弹
  7. * Class AlertException
  8. * @package App\Exceptions
  9. */
  10. class AlertException extends Exception
  11. {
  12. public function __construct(string $message = "", int $code = 400, 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. }