DBException.php 751 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Throwable;
  5. /**
  6. * 数据库DB的异常
  7. * Class DBException
  8. * @package App\Exceptions
  9. */
  10. class DBException extends Exception
  11. {
  12. public function __construct(string $message = "", int $code = 501, 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' => 500,
  27. 'error' => $this->getMessage(),
  28. 'message' => '网络异常,请稍后重试![DB]'
  29. ]);
  30. }
  31. }