use of com.baidu.dsp.common.vo.JsonObjectBase in project disconf by knightliao.
the class MyExceptionHandler method paramError.
/**
* 参数错误
*
* @param paramErrors
* @param errorCode
*
* @return
*/
private ModelAndView paramError(Map<String, String> paramErrors, ErrorCode errorCode) {
JsonObjectBase jsonObject = JsonObjectUtils.buildFieldError(paramErrors, errorCode);
LOG.warn(jsonObject.toString());
return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
use of com.baidu.dsp.common.vo.JsonObjectBase in project disconf by knightliao.
the class MyExceptionHandler method getParamErrors.
/**
* TypeMismatchException中获取到参数错误类型
*
* @param e
*/
private ModelAndView getParamErrors(TypeMismatchException e) {
Throwable t = e.getCause();
if (t instanceof ConversionFailedException) {
ConversionFailedException x = (ConversionFailedException) t;
TypeDescriptor type = x.getTargetType();
Annotation[] annotations = type != null ? type.getAnnotations() : new Annotation[0];
Map<String, String> errors = new HashMap<String, String>();
for (Annotation a : annotations) {
if (a instanceof RequestParam) {
errors.put(((RequestParam) a).value(), "parameter type error!");
}
}
if (errors.size() > 0) {
return paramError(errors, ErrorCode.TYPE_MIS_MATCH);
}
}
JsonObjectBase jsonObject = JsonObjectUtils.buildGlobalError("parameter type error!", ErrorCode.TYPE_MIS_MATCH);
return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
use of com.baidu.dsp.common.vo.JsonObjectBase in project disconf by knightliao.
the class WebCommonInterceptor method returnJsonSystemError.
/**
* 自定义的全局错误
*
* @param request
* @param response
* @param message
* @param errorCode
*
* @throws IOException
*/
protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response, String message, ErrorCode errorCode) throws IOException {
JsonObjectBase jsonObjectBase = JsonObjectUtils.buildGlobalError(message, errorCode);
response.setHeader("Cache-Control", "no-cache");
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(JsonUtils.toJson(jsonObjectBase));
}
use of com.baidu.dsp.common.vo.JsonObjectBase in project disconf by knightliao.
the class MyExceptionHandler method getParamErrors.
/**
* 参数转换出错
*
* @param e
*
* @return
*/
private ModelAndView getParamErrors(InvalidPropertyException e) {
Map<String, String> errorMap = new HashMap<String, String>();
errorMap.put(e.getPropertyName(), " parameter cannot find");
JsonObjectBase jsonObject = JsonObjectUtils.buildFieldError(errorMap, ErrorCode.TYPE_MIS_MATCH);
return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
Aggregations