GatewayExceptionHandler.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //package com.ydd.gateway.handler;
  2. //
  3. //import com.ydd.common.utils.ServletUtils;
  4. //import org.springframework.cloud.gateway.support.NotFoundException;
  5. //import org.slf4j.Logger;
  6. //import org.slf4j.LoggerFactory;
  7. //import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
  8. //import org.springframework.context.annotation.Configuration;
  9. //import org.springframework.core.annotation.Order;
  10. //import org.springframework.http.server.reactive.ServerHttpResponse;
  11. //import org.springframework.web.server.ResponseStatusException;
  12. //import org.springframework.web.server.ServerWebExchange;
  13. //import reactor.core.publisher.Mono;
  14. //
  15. ///**
  16. // * 网关统一异常处理
  17. // *
  18. // * @author ruoyi
  19. // */
  20. //@Order(-1)
  21. //@Configuration
  22. //public class GatewayExceptionHandler implements ErrorWebExceptionHandler
  23. //{
  24. // private static final Logger log = LoggerFactory.getLogger(GatewayExceptionHandler.class);
  25. //
  26. // @Override
  27. // public Mono<Void> handle(ServerWebExchange exchange, Throwable ex)
  28. // {
  29. // ServerHttpResponse response = exchange.getResponse();
  30. //
  31. // if (exchange.getResponse().isCommitted())
  32. // {
  33. // return Mono.error(ex);
  34. // }
  35. //
  36. // String msg;
  37. //
  38. // if (ex instanceof NotFoundException)
  39. // {
  40. // msg = "服务未找到";
  41. // }
  42. // else if (ex instanceof ResponseStatusException)
  43. // {
  44. // ResponseStatusException responseStatusException = (ResponseStatusException) ex;
  45. // msg = responseStatusException.getMessage();
  46. // }
  47. // else
  48. // {
  49. // msg = "内部服务器错误";
  50. // }
  51. //
  52. // log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex.getMessage());
  53. //
  54. // return ServletUtils.webFluxResponseWriter(response, msg);
  55. // }
  56. //}