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

io.sphere.internal.errors.ErrorHandling Maven / Gradle / Ivy

There is a newer version: 0.72.1
Show newest version
package io.sphere.internal.errors;

import com.google.common.base.Function;
import io.sphere.client.SphereError;
import io.sphere.client.exceptions.SphereBackendException;
import io.sphere.client.exceptions.SphereException;

import static io.sphere.internal.util.Util.getSingleError;

public class ErrorHandling {
    public static Function handleDuplicateField(final String fieldName, final SphereException exceptionToEmit) {
        return new Function() {
            public SphereException apply(SphereBackendException e) {
                SphereError.DuplicateField err = getSingleError(e, SphereError.DuplicateField.class);
                if (err != null && err.getField().equals(fieldName)) {
                    return exceptionToEmit;
                }
                return null;
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy