private Context handleException()

in safeguard-impl/src/main/java/org/apache/safeguard/impl/retry/BaseRetryInterceptor.java [103:125]


    private Context handleException(final Map<String, Object> contextData, final String contextKey,
                                    final Model modelRef, final Exception error) throws Exception {
        if (CircuitBreakerOpenException.class.isInstance(error)) {
            throw error;
        }

        // refresh the counter from the other interceptors
        final Context ctx = Context.class.cast(contextData.get(contextKey));

        if (modelRef.abortOn(error) || (--ctx.counter) < 0 || System.nanoTime() >= ctx.maxEnd) {
            executeFinalCounterAction(contextData, modelRef.callsFailed);
            throw error;
        }
        if (!modelRef.retryOn(error)) {
            throw error;
        }
        modelRef.retries.inc();
        final long pause = modelRef.nextPause();
        if (pause > 0) {
            Thread.sleep(pause);
        }
        return ctx;
    }