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

com.turbospaces.okhttp.UnexpectedHttpClientException Maven / Gradle / Ivy

The newest version!
package com.turbospaces.okhttp;

import com.turbospaces.http.UnexpectedHttpStatusException;
import lombok.Getter;
import okhttp3.Headers;
import okhttp3.Response;

import java.util.List;
import java.util.Optional;

@Getter
public class UnexpectedHttpClientException extends UnexpectedHttpStatusException {
    private final Headers headers;

    public UnexpectedHttpClientException(Response response, String entity) {
        super(String.format("%s %s %s", response.protocol(), response.code(), response.message()),
                entity,
                response.code());
        this.headers = response.headers();
    }
    @Override
    public List getHeaderValues(String key) {
        return this.headers.values(key);
    }
    @Override
    public Optional getFirstHeaderValue(String key) {
        // Returns the last value corresponding to the specified field, or null.
        return Optional.ofNullable(this.headers.get(key));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy