use of io.leopard.web.view.StatusCodeException in project leopard by tanhaichao.
the class JsonViewTrynbResolver method resolveView.
@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
// Class<?> returnType = handler.getMethod().getReturnType();
// if (!JsonView.class.isAssignableFrom(returnType)) {
ResponseBody body = handler.getMethodAnnotation(ResponseBody.class);
if (body == null) {
return null;
}
if (corsConfig.isEnable()) {
// response.addHeader("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With,Content-Type");
// response.addHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String allowOrigin = corsConfig.getAccessControlAllowOrigin(request);
if (StringUtils.isNotEmpty(allowOrigin)) {
response.addHeader("Access-Control-Allow-Origin", allowOrigin);
response.addHeader("Access-Control-Allow-Credentials", "true");
// response.addHeader("Access-Control-Allow-Methods", "POST");
// response.addHeader("Access-Control-Allow-Headers", "x_requested_with,content-type");
}
}
ErrorJsonView jsonView = new ErrorJsonView();
jsonView.setException(exception);
jsonView.setHandler(handler);
if (exception instanceof StatusCodeException) {
StatusCodeException e = (StatusCodeException) exception;
jsonView.setStatus(e.getStatus());
} else {
jsonView.setStatus(trynbInfo.getStatusCode());
}
jsonView.setMessage(trynbInfo.getMessage());
if (trynbInfo.isTrynbMessage() || trynbInfo.isApiMessage() || trynbInfo.isTranslate()) {
jsonView.setOriginalMessage(ErrorUtil.parseMessage(exception));
}
if (SystemUtils.IS_OS_WINDOWS) {
// TODO 测试代码
jsonView.setDetailMessage(exception.getMessage());
}
jsonView.setException(exception.getClass().getName());
return jsonView;
}
use of io.leopard.web.view.StatusCodeException in project leopard by tanhaichao.
the class WsViewTrynbResolver method resolveView.
@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
Class<?> returnType = handler.getMethod().getReturnType();
if (!returnType.equals(WsView.class)) {
return null;
}
WsView webserviceView = new WsView(null);
if (exception instanceof StatusCodeException) {
StatusCodeException e = (StatusCodeException) exception;
webserviceView.setStatus(e.getStatus());
webserviceView.setMessage(e.getMessage());
} else {
webserviceView.setStatus(trynbInfo.getStatusCode());
webserviceView.setMessage(trynbInfo.getMessage());
}
return webserviceView;
}
Aggregations