protected void handleConnectCompletion(
            ChannelFuture cf, Promise<PooledConnection> callerPromise, CurrentPassport passport) {
        connCreationsInProgress.decrementAndGet();
        updateServerStatsOnConnectCompletion(cf);
        if (cf.isSuccess()) {
            passport.add(PassportState.ORIGIN_CH_CONNECTED);
            createConnSucceededCounter.increment();
            connsInUse.incrementAndGet();
            createConnection(cf, callerPromise, passport);
        } else {
            createConnFailedCounter.increment();

            // unwrap DecoderExceptions to get a better indication of why decoding failed
            // as decoding failures are not indicative of actual connection causes
            if (cf.cause() instanceof DecoderException de && de.getCause() != null) {
                callerPromise.setFailure(new OriginConnectException(
                        de.getCause().getMessage(), de.getCause(), OutboundErrorType.CONNECT_ERROR));
            } else {
                callerPromise.setFailure(new OriginConnectException(
                        cf.cause().getMessage(), cf.cause(), OutboundErrorType.CONNECT_ERROR));
            }
        }
    }
@Test
    void handleConnectCompletionWithDecoderExceptionIsUnwrapped() {

        EmbeddedChannel channel = new EmbeddedChannel();
        Promise<PooledConnection> promise = CLIENT_EVENT_LOOP.newPromise();
        pool.handleConnectCompletion(
                channel.newFailedFuture(new DecoderException(new SSLHandshakeException("Invalid tls cert"))),
                promise,
                CurrentPassport.create());

        assertFalse(promise.isSuccess());
        assertNotNull(promise.cause());
        assertInstanceOf(OriginConnectException.class, promise.cause());
        assertInstanceOf(
                SSLHandshakeException.class, promise.cause().getCause(), "expect decoder exception is unwrapped");
    }