summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/ServerResponseException.java
blob: 2d105aec30b2f2be8c8a8274a8e7bb50b9ccabc3 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.core;

import com.google.common.annotations.Beta;

/**
 * The request was not processed properly on the server.
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 * @since 5.1.20
 */
@SuppressWarnings("serial")
@Beta
public class ServerResponseException extends Exception {
    private final int responseCode;
    private final String responseString;

    public ServerResponseException(int responseCode, String responseString) {
        super(responseString);
        this.responseCode = responseCode;
        this.responseString = responseString;
    }

    public ServerResponseException(String responseString) {
        super(responseString);
        this.responseCode = 0;
        this.responseString = responseString;
    }

    @Override
    public String toString() {
        if (responseCode > 0) {
            return responseCode + ": " + responseString;
        }
        return responseString;
    }
}