public static ConnectorException handleConnectionError(Throwable error) {
        ConnectorException ce = null;
        if (error instanceof UnknownHostException || error instanceof ConnectException || error instanceof NoRouteToHostException) {
            ce = new ConnectorException("Unable to connect to backend", error); //$NON-NLS-1$
            ce.setStatusCode(502); // BAD GATEWAY
        } else if (error instanceof InterruptedIOException || error instanceof java.util.concurrent.TimeoutException) {
            ce = new ConnectorException("Connection to backend terminated. " + error.getMessage(), error); //$NON-NLS-1$
            ce.setStatusCode(504); // GATEWAY TIMEOUT

        }
        if (ce != null) {
            return ce;
        } else {
            return new ConnectorException(error.getMessage(), error);
        }
    }
This method handles a connection error that was caused while connecting the gateway to the backend.

@param error the connection error to be handled
@return a new ConnectorException
gateway/engine/core/src/main/java/io/apiman/gateway/engine/handler/ErrorHandler.java