GlobalExceptionHandler.java 646B

12345678910111213141516171819
  1. package com.example.zijincao.exception;
  2. import com.example.zijincao.common.ResponseBean;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. import org.springframework.web.bind.annotation.RestControllerAdvice;
  7. @Slf4j
  8. @RestControllerAdvice
  9. public class GlobalExceptionHandler {
  10. @ResponseBody
  11. @ExceptionHandler(Exception.class)
  12. public ResponseBean handleException(Exception e){
  13. log.error(e.getMessage(),e);
  14. return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
  15. }
  16. }