GlobalExceptionHandler.java 803 B

1234567891011121314151617181920212223242526
  1. package com.webflux.launchadmin.global;
  2. import com.webflux.launchcommon.returnObj.RW;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.http.HttpStatus;
  5. import org.springframework.web.bind.annotation.ExceptionHandler;
  6. import org.springframework.web.bind.annotation.ResponseBody;
  7. import org.springframework.web.bind.annotation.ResponseStatus;
  8. import org.springframework.web.bind.annotation.RestControllerAdvice;
  9. import reactor.core.publisher.Mono;
  10. @RestControllerAdvice
  11. @Slf4j
  12. public class GlobalExceptionHandler {
  13. @ResponseBody
  14. @ResponseStatus(HttpStatus.BAD_REQUEST)
  15. @ExceptionHandler(Exception.class)
  16. public Mono<RW<Object>> handleException(Exception e) {
  17. log.error(e.toString());
  18. return RW.fail("500",e.getMessage(),Mono.just(e.getMessage()));
  19. }
  20. }