@Override public void handleError(ClientHttpResponse response) throws IOException { LOGGER.info("request id '{}' error response '{}'", ServletContextHolder.fetchRequestId(), response); } }
@Before(value = "within(com.github.prontera..*) " + "&& (@annotation(org.springframework.web.bind.annotation.ResponseBody)" + "|| @annotation(org.springframework.web.bind.annotation.RequestMapping))") public void before(JoinPoint joinPoint) { final String requestId = ServletContextHolder.fetchRequestId(); final HttpServletResponse response = ServletContextHolder.getResponse(); if (response.getHeader(RequestAttributeConst.REQUEST_ID) == null) { response.addHeader(RequestAttributeConst.REQUEST_ID, requestId); } }
/** * 获取错误的字段名, 如果被{@link JsonProperty}修饰则优先选择 * * @see JsonProperty */ private static String acquireFieldName(BindingResult result, FieldError fieldError) { Preconditions.checkNotNull(result); Preconditions.checkNotNull(fieldError); // 获取错误字段名 String errorFieldName = fieldError.getField(); // 获取校验非法的类 Class<?> clazz = result.getTarget().getClass(); final Field field; try { // 获取其字段名 field = clazz.getDeclaredField(fieldError.getField()); final JsonProperty annotation = field.getAnnotation(JsonProperty.class); // 若JsonProperty里value()不为null则覆盖该值 if (annotation != null) { errorFieldName = annotation.value(); } } catch (NoSuchFieldException e) { Throwables.throwIfUnchecked(e); LOGGER.error("request id: {}, 反射字段名时抛出异常: {}", ServletContextHolder.fetchRequestId(), e.getMessage()); } return errorFieldName; }
final String errorMessage = fieldError.getDefaultMessage(); LOGGER.debug("request id: {}, error field: {}, error msg: {}", ServletContextHolder.fetchRequestId(), errorFieldName, errorMessage); errorMap.put(errorFieldName, errorMessage);