package com.happy.interceptor; import com.alibaba.fastjson.JSONObject; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @ControllerAdvice public class GloablExceptionHandler { @ResponseBody @ExceptionHandler(Exception.class) public Object handleException(Exception e) { String msg = e.getMessage(); JSONObject jsonObject = JSONObject.parseObject(msg); return jsonObject; } }