aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedProtocolException.java
blob: dd5aa902c1a2c9171837ef36989d032bb08d3128 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client;

import com.yahoo.vespa.http.client.config.Endpoint;

/**
 * An exception thrown when a feed endpoint returns an error during feeding.
 *
 * @author bjorncs
 */
public class FeedProtocolException extends FeedEndpointException {

    private final int httpStatusCode;
    private final String httpResponseMessage;

    public FeedProtocolException(int httpStatusCode,
                                 String httpResponseMessage,
                                 Throwable cause,
                                 Endpoint endpoint) {
        super(createMessage(httpStatusCode, httpResponseMessage, endpoint), cause, endpoint);
        this.httpStatusCode = httpStatusCode;
        this.httpResponseMessage = httpResponseMessage;
    }

    private static String createMessage(int httpStatusCode,
                                        String httpResponseMessage,
                                        Endpoint endpoint) {
        return String.format("Endpoint '%s:%d' returned an error on handshake: %d - %s",
                             endpoint.getHostname(),
                             endpoint.getPort(),
                             httpStatusCode,
                             httpResponseMessage);
    }

    public int getHttpStatusCode() {
        return httpStatusCode;
    }

    public String getHttpResponseMessage() {
        return httpResponseMessage;
    }
}