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

io.castle.client.internal.utils.OkHttpExceptionUtil Maven / Gradle / Ivy

Go to download

Castle adds real-time monitoring of your authentication stack, instantly notifying you and your users on potential account hijacks.

There is a newer version: 2.4.3
Show newest version
package io.castle.client.internal.utils;

import io.castle.client.model.CastleApiInternalServerErrorException;
import io.castle.client.model.CastleApiTimeoutException;
import io.castle.client.model.CastleRuntimeException;
import io.castle.client.model.CastleServerErrorException;
import okhttp3.Response;

import java.io.IOException;
import java.net.SocketTimeoutException;

public class OkHttpExceptionUtil {

    public static CastleRuntimeException handle(IOException e) {
        if (e instanceof SocketTimeoutException) {
            return new CastleApiTimeoutException(e);
        }
        return new CastleRuntimeException(e);
    }

    public static void handle(Response response) throws CastleServerErrorException {
        if (!response.isSuccessful() && !response.isRedirect()) {
            if (response.code() == 500) {
                throw new CastleApiInternalServerErrorException(response);
            }
            throw new CastleServerErrorException(response);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy