Search in sources :

Example 1 with TrynbInfo

use of io.leopard.mvc.trynb.model.TrynbInfo in project leopard by tanhaichao.

the class TrynbHandlerExceptionResolver method resolveException.

// @PostConstruct
// public void init() {
// for (TrynbResolver trynbResolver : trynbResolverList) {
// logger.info("trynbResolver:" + trynbResolver.getClass().getName());
// }
// }
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
    if (exception == null) {
        throw new NullPointerException("exception参数怎么会为null?");
    }
    // logger.error("resolveException:" + exception.toString());
    if (!(handler instanceof HandlerMethod)) {
        return null;
    }
    String uri = request.getRequestURI();
    TrynbInfo trynbInfo = errorPageService.parse(request, uri, exception);
    ModelAndView view = resolveView(request, response, ((HandlerMethod) handler), exception, trynbInfo);
    request.setAttribute("exception", exception);
    // request.setAttribute("modelAndView", view);
    return view;
}
Also used : TrynbInfo(io.leopard.mvc.trynb.model.TrynbInfo) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 2 with TrynbInfo

use of io.leopard.mvc.trynb.model.TrynbInfo in project leopard by tanhaichao.

the class TrynbApiImpl method parse.

@Override
public TrynbInfo parse(TrynbLogger trynbLogger, HttpServletRequest request, String uri, Exception exception) {
    ErrorConfig errorConfig = trynbDao.find(uri);
    if (exception instanceof MethodArgumentTypeMismatchException) {
        MethodArgumentTypeMismatchException e2 = (MethodArgumentTypeMismatchException) exception;
        Exception e = (Exception) e2.getCause().getCause();
        if (e != null) {
            exception = e;
        } else {
            exception = (Exception) e2.getCause();
        }
    }
    ExceptionConfig exceptionConfig = this.find(errorConfig, exception);
    TrynbInfo trynbInfo = new TrynbInfo();
    String message;
    if (exceptionConfig == null || StringUtils.isEmpty(exceptionConfig.getMessage())) {
        message = parseMessage(trynbInfo, exception);
    } else {
        message = exceptionConfig.getMessage();
        trynbInfo.setTrynbMessage(true);
    }
    String statusCode = this.parseStatusCode(trynbLogger, exceptionConfig, request, uri, exception);
    trynbInfo.setPage(errorConfig.getPage());
    trynbInfo.setMessage(message);
    trynbInfo.setException(exception);
    trynbInfo.setStatusCode(statusCode);
    return trynbInfo;
}
Also used : MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException) TrynbInfo(io.leopard.mvc.trynb.model.TrynbInfo) ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig) ApiException(io.leopard.core.exception.ApiException) MethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)

Aggregations

TrynbInfo (io.leopard.mvc.trynb.model.TrynbInfo)2 ApiException (io.leopard.core.exception.ApiException)1 ErrorConfig (io.leopard.mvc.trynb.model.ErrorConfig)1 ExceptionConfig (io.leopard.mvc.trynb.model.ExceptionConfig)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 MethodArgumentTypeMismatchException (org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1