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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

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
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import java.net.URL;
23

24
/**
25
 * This exception is thrown when an Http error (response code 4xx or 5xx) is detected.
26
 **/
27
public class HttpException extends RuntimeException {
28

29
    /** The Constant serialVersionUID. */
30
    private static final long serialVersionUID = 1L;
31

32
    /**
33
     * throw a http Exception with the given responseCode.
34
     *
35
     * @param responseCode
36
     *            the response code
37
     */
38
    protected HttpException(int responseCode) {
×
39
        _responseCode = responseCode;
×
40
        System.err.println(responseCode);
×
41
    }
×
42

43
    /**
44
     * throw a http Exception with the given responseCode and cause.
45
     *
46
     * @param responseCode
47
     *            the response code
48
     * @param cause
49
     *            the cause
50
     */
51
    protected HttpException(int responseCode, Throwable cause) {
×
52
        _responseCode = responseCode;
×
53
        _cause = cause;
×
54
    }
×
55

56
    /**
57
     * throw a http Exception with the given responseCode and Message and base url.
58
     *
59
     * @param responseCode
60
     *            the response code
61
     * @param responseMessage
62
     *            the response message
63
     * @param baseURL
64
     *            the base URL
65
     */
66
    protected HttpException(int responseCode, String responseMessage, URL baseURL) {
1✔
67
        _responseMessage = responseMessage;
1✔
68
        _responseCode = responseCode;
1✔
69
        _url = baseURL;
1✔
70
    }
1✔
71

72
    /**
73
     * throw a http Exception with the given responseCode and Message, base url and cause.
74
     *
75
     * @param responseCode
76
     *            the response code
77
     * @param responseMessage
78
     *            the response message
79
     * @param baseURL
80
     *            the base URL
81
     * @param cause
82
     *            the cause
83
     */
84
    protected HttpException(int responseCode, String responseMessage, URL baseURL, Throwable cause) {
×
85
        _responseMessage = responseMessage;
×
86
        _responseCode = responseCode;
×
87
        _url = baseURL;
×
88
        _cause = cause;
×
89
    }
×
90

91
    /**
92
     * get the Message for the http Exception
93
     *
94
     * @return - the message of the Exception
95
     */
96
    @Override
97
    public String getMessage() {
98
        StringBuilder sb = new StringBuilder(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE).append("Error on HTTP request: ");
1✔
99
        sb.append(_responseCode);
1✔
100
        if (_responseMessage != null) {
1!
101
            sb.append(" ");
1✔
102
            sb.append(_responseMessage);
1✔
103
            sb.append("");
1✔
104
        }
105
        if (_url != null) {
1!
106
            sb.append(" [");
1✔
107
            sb.append(_url.toExternalForm());
1✔
108
            sb.append("]");
1✔
109
        }
110
        return sb.toString();
1✔
111
    }
112

113
    /**
114
     * get the response Code of this http Exception.
115
     *
116
     * @return - the response Code code 4xx or 5xx
117
     */
118
    public int getResponseCode() {
119
        return _responseCode;
1✔
120
    }
121

122
    /**
123
     * get the response Message of this http Exception.
124
     *
125
     * @return the response message
126
     */
127
    public String getResponseMessage() {
128
        return _responseMessage;
1✔
129
    }
130

131
    /** The response code. */
132
    // private local copies of variables
133
    private int _responseCode;
134

135
    /** The url. */
136
    private URL _url;
137

138
    /** The response message. */
139
    private String _responseMessage;
140

141
    /**
142
     * get the cause (if any)
143
     */
144
    @Override
145
    public Throwable getCause() {
146
        return _cause;
×
147
    }
148

149
    /** The cause. */
150
    private Throwable _cause;
151

152
    /** The response. */
153
    // see feature request [ 914314 ] Add HttpException.getResponse for better reporting
154
    private WebResponse response;
155

156
    /**
157
     * return the WebResponse associated with this Exception (if any).
158
     *
159
     * @return the response
160
     */
161
    public WebResponse getResponse() {
162
        return response;
1✔
163
    }
164

165
    /**
166
     * add the given response to this exception.
167
     *
168
     * @param response
169
     *            the new response
170
     */
171
    public void setResponse(WebResponse response) {
172
        this.response = response;
1✔
173
    }
1✔
174

175
}
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