GloablExceptionHandler.java 578 B

123456789101112131415161718
  1. package com.happy.interceptor;
  2. import com.alibaba.fastjson.JSONObject;
  3. import org.springframework.web.bind.annotation.ControllerAdvice;
  4. import org.springframework.web.bind.annotation.ExceptionHandler;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. @ControllerAdvice
  7. public class GloablExceptionHandler {
  8. @ResponseBody
  9. @ExceptionHandler(Exception.class)
  10. public Object handleException(Exception e) {
  11. String msg = e.getMessage();
  12. JSONObject jsonObject = JSONObject.parseObject(msg);
  13. return jsonObject;
  14. }
  15. }