All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bklab.flow.exception.consumer.FluentExceptionMessageRender Maven / Gradle / Ivy

There is a newer version: 22.0.1
Show newest version
package org.bklab.flow.exception.consumer;

import org.apache.http.HttpStatus;

import java.util.Arrays;
import java.util.List;

class FluentExceptionMessageRender {

    public static final List exceptionMessageRenders = Arrays.asList(
            new SC_REQUEST_TIMEOUT(),
            new SC_REQUEST_TIMEOUT_DB(),
            new SC_REQUEST_TIMEOUT_DB1()
    );

    private static class SC_REQUEST_TIMEOUT implements IFluentExceptionMessageRender {

        @Override
        public String header() {
            return createHeader(HttpStatus.SC_REQUEST_TIMEOUT, " - 连接超时");
        }

        @Override
        public String[] className() {
            return classNames(
                    java.net.http.HttpTimeoutException.class.getName(),
                    java.net.ConnectException.class.getName()
            );
        }

        @Override
        public String message(Exception exception) {
            return "系统无法连接到指定服务器,请联系系统管理员。";
        }
    }

    private static class SC_REQUEST_TIMEOUT_DB implements IFluentExceptionMessageRender {

        @Override
        public String header() {
            return createHeader(HttpStatus.SC_REQUEST_TIMEOUT, " - 连接超时");
        }

        @Override
        public String[] className() {
            return classNames(
                    "com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException"
            );
        }

        @Override
        public String message(Exception exception) {
            return "系统无法连接到数据库服务器超时,请联系系统管理员。";
        }
    }

    private static class SC_REQUEST_TIMEOUT_DB1 implements IFluentExceptionMessageRender {

        @Override
        public String header() {
            return createHeader(HttpStatus.SC_REQUEST_TIMEOUT, " - 连接超时");
        }

        @Override
        public String[] className() {
            return classNames(
                    "com.alibaba.druid.pool.GetConnectionTimeoutException"
            );
        }

        @Override
        public String message(Exception exception) {
            return "与数据库链接超时,请稍后重试。";
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy