Search in sources :

Example 1 with ExceptionConfig

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

the class TrynbDaoXmlImpl method parseErrorConfig.

protected ErrorConfig parseErrorConfig(Element element) {
    String url = element.getAttribute("url");
    String page = element.getAttribute("page");
    List<ExceptionConfig> exceptionConfigList = new ArrayList<ExceptionConfig>();
    NodeList nodeList = element.getElementsByTagName("exception");
    int size = nodeList.getLength();
    for (int i = 0; i < size; i++) {
        Node node = nodeList.item(i);
        ExceptionConfig exceptionConfig = this.parseExceptionConfig((Element) node);
        exceptionConfigList.add(exceptionConfig);
    }
    ErrorConfig errorConfig = new ErrorConfig();
    errorConfig.setUrl(url);
    errorConfig.setPage(page);
    errorConfig.setExceptionConfigList(exceptionConfigList);
    return errorConfig;
}
Also used : ErrorConfig(io.leopard.mvc.trynb.model.ErrorConfig) ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 2 with ExceptionConfig

use of io.leopard.mvc.trynb.model.ExceptionConfig 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)

Example 3 with ExceptionConfig

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

the class TrynbApiImpl method find.

protected ExceptionConfig find(ErrorConfig errorConfig, Exception exception) {
    List<ExceptionConfig> exceptionConfigList = errorConfig.getExceptionConfigList();
    String exceptionClassName = exception.getClass().getName();
    for (ExceptionConfig exceptionConfig : exceptionConfigList) {
        boolean match = match(exceptionConfig.getType(), exceptionClassName);
        if (match) {
            return exceptionConfig;
        }
    }
    return null;
}
Also used : ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig)

Example 4 with ExceptionConfig

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

the class TrynbDaoXmlImpl method parseExceptionConfig.

protected ExceptionConfig parseExceptionConfig(Element element) {
    String type = element.getAttribute("type");
    String statusCode = element.getAttribute("statusCode").trim();
    String message = element.getAttribute("message");
    String log = element.getAttribute("log");
    ExceptionConfig exceptionConfig = new ExceptionConfig();
    exceptionConfig.setType(type);
    exceptionConfig.setMessage(message);
    exceptionConfig.setStatusCode(statusCode);
    exceptionConfig.setLog(log);
    return exceptionConfig;
}
Also used : ExceptionConfig(io.leopard.mvc.trynb.model.ExceptionConfig)

Aggregations

ExceptionConfig (io.leopard.mvc.trynb.model.ExceptionConfig)4 ErrorConfig (io.leopard.mvc.trynb.model.ErrorConfig)2 ApiException (io.leopard.core.exception.ApiException)1 TrynbInfo (io.leopard.mvc.trynb.model.TrynbInfo)1 ArrayList (java.util.ArrayList)1 MethodArgumentTypeMismatchException (org.springframework.web.method.annotation.MethodArgumentTypeMismatchException)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1