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

syncloud.google.docs.SensitiveRequestRetryer Maven / Gradle / Ivy

The newest version!
package syncloud.google.docs;

import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import syncloud.core.log.Logger;

import java.io.IOException;

public class SensitiveRequestRetryer extends ExponentialBackoff {
    private static Logger logger = Logger.getLogger(SensitiveRequestRetryer.class);
    private HttpRequest request;

    public HttpResponse execute(HttpRequest request) throws IOException {
        this.request = request;
        return run();
    }

    @Override
    public HttpResponse process() throws NotReady, IOException {
        try {
            HttpResponse response = request.execute();
            HttpLogger.log(response);
            return response;
        } catch (HttpResponseException e) {
            HttpResponse response = e.getResponse();
            int code = response.getStatusCode();
            HttpLogger.log(response);
            if (/*code == 500 || */code == 400) {
                logger.error("error: " + e.getMessage());
                throw new NotReady();
            } else {
                throw e;
            }
        } catch (IOException e) {
            logger.error("error: " + e.getMessage());
            throw e;
        }
    }

    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy