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

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

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
    private static final long serialVersionUID = 1L;
30

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

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

52
    /**
53
     * throw a http Exception with the given responseCode and Message and base url
54
     *
55
     * @param responseCode
56
     * @param responseMessage
57
     * @param baseURL
58
     */
59
    protected HttpException(int responseCode, String responseMessage, URL baseURL) {
1✔
60
        _responseMessage = responseMessage;
1✔
61
        _responseCode = responseCode;
1✔
62
        _url = baseURL;
1✔
63
    }
1✔
64

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

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

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

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

120
    // private local copies of variables
121
    private int _responseCode;
122
    private URL _url;
123
    private String _responseMessage;
124

125
    /**
126
     * get the cause (if any)
127
     */
128
    @Override
129
    public Throwable getCause() {
130
        return _cause;
×
131
    }
132

133
    private Throwable _cause;
134

135
    // see feature request [ 914314 ] Add HttpException.getResponse for better reporting
136
    private WebResponse response;
137

138
    /**
139
     * return the WebResponse associated with this Exception (if any)
140
     *
141
     * @return
142
     */
143
    public WebResponse getResponse() {
144
        return response;
1✔
145
    }
146

147
    /**
148
     * add the given response to this exception
149
     *
150
     * @param response
151
     */
152
    public void setResponse(WebResponse response) {
153
        this.response = response;
1✔
154
    }
1✔
155

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