• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.5
/src/main/java/com/meterware/httpunit/HttpException.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import java.net.URL;
11

12
/**
13
 * This exception is thrown when an Http error (response code 4xx or 5xx) is detected.
14
 **/
15
public class HttpException extends RuntimeException {
16

17
    /** The Constant serialVersionUID. */
18
    private static final long serialVersionUID = 1L;
19

20
    /**
21
     * throw a http Exception with the given responseCode.
22
     *
23
     * @param responseCode
24
     *            the response code
25
     */
26
    protected HttpException(int responseCode) {
×
27
        _responseCode = responseCode;
×
28
        System.err.println(responseCode);
×
29
    }
×
30

31
    /**
32
     * throw a http Exception with the given responseCode and cause.
33
     *
34
     * @param responseCode
35
     *            the response code
36
     * @param cause
37
     *            the cause
38
     */
39
    protected HttpException(int responseCode, Throwable cause) {
×
40
        _responseCode = responseCode;
×
41
        _cause = cause;
×
42
    }
×
43

44
    /**
45
     * throw a http Exception with the given responseCode and Message and base url.
46
     *
47
     * @param responseCode
48
     *            the response code
49
     * @param responseMessage
50
     *            the response message
51
     * @param baseURL
52
     *            the base URL
53
     */
54
    protected HttpException(int responseCode, String responseMessage, URL baseURL) {
1✔
55
        _responseMessage = responseMessage;
1✔
56
        _responseCode = responseCode;
1✔
57
        _url = baseURL;
1✔
58
    }
1✔
59

60
    /**
61
     * throw a http Exception with the given responseCode and Message, base url and cause.
62
     *
63
     * @param responseCode
64
     *            the response code
65
     * @param responseMessage
66
     *            the response message
67
     * @param baseURL
68
     *            the base URL
69
     * @param cause
70
     *            the cause
71
     */
72
    protected HttpException(int responseCode, String responseMessage, URL baseURL, Throwable cause) {
×
73
        _responseMessage = responseMessage;
×
74
        _responseCode = responseCode;
×
75
        _url = baseURL;
×
76
        _cause = cause;
×
77
    }
×
78

79
    /**
80
     * get the Message for the http Exception
81
     *
82
     * @return - the message of the Exception
83
     */
84
    @Override
85
    public String getMessage() {
86
        StringBuilder sb = new StringBuilder(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE).append("Error on HTTP request: ");
1✔
87
        sb.append(_responseCode);
1✔
88
        if (_responseMessage != null) {
1!
89
            sb.append(" ");
1✔
90
            sb.append(_responseMessage);
1✔
91
            sb.append("");
1✔
92
        }
93
        if (_url != null) {
1!
94
            sb.append(" [");
1✔
95
            sb.append(_url.toExternalForm());
1✔
96
            sb.append("]");
1✔
97
        }
98
        return sb.toString();
1✔
99
    }
100

101
    /**
102
     * get the response Code of this http Exception.
103
     *
104
     * @return - the response Code code 4xx or 5xx
105
     */
106
    public int getResponseCode() {
107
        return _responseCode;
1✔
108
    }
109

110
    /**
111
     * get the response Message of this http Exception.
112
     *
113
     * @return the response message
114
     */
115
    public String getResponseMessage() {
116
        return _responseMessage;
1✔
117
    }
118

119
    /** The response code. */
120
    // private local copies of variables
121
    private int _responseCode;
122

123
    /** The url. */
124
    private URL _url;
125

126
    /** The response message. */
127
    private String _responseMessage;
128

129
    /**
130
     * get the cause (if any)
131
     */
132
    @Override
133
    public Throwable getCause() {
134
        return _cause;
×
135
    }
136

137
    /** The cause. */
138
    private Throwable _cause;
139

140
    /** The response. */
141
    // see feature request [ 914314 ] Add HttpException.getResponse for better reporting
142
    private WebResponse response;
143

144
    /**
145
     * return the WebResponse associated with this Exception (if any).
146
     *
147
     * @return the response
148
     */
149
    public WebResponse getResponse() {
150
        return response;
1✔
151
    }
152

153
    /**
154
     * add the given response to this exception.
155
     *
156
     * @param response
157
     *            the new response
158
     */
159
    public void setResponse(WebResponse response) {
160
        this.response = response;
1✔
161
    }
1✔
162

163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc