SystemExceptionHandler

    xiaoxiao2025-04-11  23

    @ControllerAdvice @Slf4j public class SystemExceptionHandler { /** * @ExceptionHandler 匹配抛出自定义的异常类型 MyException * 如果返回的是json格式,需要加上@ResponsBody */ @ExceptionHandler(value = SystemException.class) @ResponseBody public Object jsonErrorHandler(HttpServletRequest request, SystemException e) throws Exception { RestApiResult restApiResult = new RestApiResult(); StringBuffer msg = new StringBuffer(); Map<String, String> map = new HashMap<>(); map.put("code", e.getCode()); map.put("desc", e.getDesc()); restApiResult.setToken(request.getHeader(HttpHeaders.AUTHORIZATION)); restApiResult.setUserNo(request.getHeader(CommonConstant.MIRCOSERVICE_NAME)); restApiResult.setRet(1); restApiResult.setData(map); return restApiResult; } }
    最新回复(0)