ExceptionAdvice.java 674 B

12345678910111213141516171819
  1. package com.koobietech.eas.config;
  2. import com.koobietech.eas.common.result.JsonResult;
  3. import org.springframework.http.HttpStatus;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. import org.springframework.web.bind.annotation.ResponseStatus;
  7. import org.springframework.web.bind.annotation.RestControllerAdvice;
  8. @RestControllerAdvice
  9. public class ExceptionAdvice {
  10. @ResponseBody
  11. @ResponseStatus(HttpStatus.OK)
  12. @ExceptionHandler(Exception.class)
  13. public JsonResult exceptionHandler(Exception e){
  14. e.printStackTrace();
  15. return JsonResult.fail(e.getMessage());
  16. }
  17. }