Http.php 772 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\exception;
  3. use think\exception\Handle;
  4. use think\exception\HttpException;
  5. use think\exception\ValidateException;
  6. use think\Response;
  7. use Throwable;
  8. class Http extends Handle
  9. {
  10. public function render($request, Throwable $e): Response
  11. {
  12. // 参数验证错误
  13. if ($e instanceof ValidateException) {
  14. //return json($e->getError(), 422);
  15. to_assign(1, $e->getError(), [], '', 422);
  16. }
  17. // 请求异常
  18. if ($e instanceof HttpException && $request->isAjax()) {
  19. //return response($e->getMessage(), $e->getStatusCode());
  20. to_assign(1, $e->getMessage(), [], '', $e->getStatusCode());
  21. }
  22. // 其他错误交给系统处理
  23. return parent::render($request, $e);
  24. }
  25. }