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

jp.gopay.sdk.builders.RetryUtils Maven / Gradle / Ivy

package jp.gopay.sdk.builders;

import jp.gopay.sdk.models.errors.DetailedError;
import jp.gopay.sdk.models.errors.GoPayException;
import jp.gopay.sdk.utils.functions.ErrorHandler;
import jp.gopay.sdk.utils.functions.Function;
import jp.gopay.sdk.utils.functions.GopayFunctions;
import jp.gopay.sdk.utils.functions.Predicate;

public abstract class RetryUtils {

    public static >> Request retryIgnoringDescriptor(Request originalRequest, final DescriptorRetry builder){
        return GopayFunctions.retry(
                originalRequest,
                new ErrorHandler<>(
                        new Predicate() {
                            @Override
                            public boolean test(Throwable t) {
                                return GoPayException.class.isInstance(t) &&
                                        ((GoPayException)t)
                                                .getBody()
                                                .getErrors()
                                                .contains(new DetailedError(
                                                        "descriptor",
                                                        "NOT_SUPPORTED_BY_PROCESSOR")
                                                );
                            }
                        },
                        new Function>() {
                            @Override
                            public Request apply(Throwable arg) {
                                return builder.withDescriptor(null).build();
                            }
                        }
                )
        );
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy