
io.sphere.internal.request.FetchRequestWithErrorHandling Maven / Gradle / Ivy
package io.sphere.internal.request;
import com.google.common.base.Optional;
import io.sphere.internal.util.Util;
import io.sphere.client.FetchRequest;
import com.google.common.util.concurrent.ListenableFuture;
import org.codehaus.jackson.type.TypeReference;
public class FetchRequestWithErrorHandling implements FetchRequest, TestableRequest {
RequestHolder requestHolder;
int handledErrorStatus;
TypeReference jsonParserTypeRef;
public FetchRequestWithErrorHandling(RequestHolder requestHolder, int handledErrorStatus, TypeReference jsonParserTypeRef) {
if (requestHolder == null) throw new NullPointerException("requestHolder");
if (jsonParserTypeRef == null) throw new NullPointerException("jsonParserTypeRef");
this.requestHolder = requestHolder;
this.handledErrorStatus = handledErrorStatus;
this.jsonParserTypeRef = jsonParserTypeRef;
}
@Override public Optional fetch() {
return Util.sync(fetchAsync());
}
@Override public ListenableFuture> fetchAsync() {
return RequestExecutor.executeAndHandleError(requestHolder, handledErrorStatus, jsonParserTypeRef);
}
@Override public FetchRequest expand(String... paths) {
for (String path: paths) {
requestHolder.addQueryParameter("expand", path);
}
return this;
}
// testing purposes
@Override public TestableRequestHolder getRequestHolder() {
return requestHolder;
}
// logging and debugging purposes
@Override public String toString() {
return getRequestHolder().toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy