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

io.tus.java.client.ProtocolException Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package io.tus.java.client;

import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * This exception is thrown if the server sends a request with an unexpected status code or
 * missing/invalid headers.
 */
public class ProtocolException extends Exception {
    private HttpURLConnection connection;

    public ProtocolException(String message) {
        super(message);
    }

    public ProtocolException(String message, HttpURLConnection connection) {
        super(message);
        this.connection = connection;
    }

    public HttpURLConnection getCausingConnection() {
        return connection;
    }

    public boolean shouldRetry() {
        if(connection == null) {
            return false;
        }

        try {
            int responseCode = connection.getResponseCode();

            // 5XX and 423 Resource Locked status codes should be retried.
            return (responseCode >= 500 && responseCode < 600) || responseCode == 423;
        } catch(IOException e) {
            return false;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy