Skip to content

Commit b2299dc

Browse files
Fix typo
Use IllegalArgumentException instead of Runtime Add bounds checking to all range methods Add doc to another method
1 parent 3c8b3ab commit b2299dc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • extractor/src/main/java/org/schabi/newpipe/extractor/downloader

extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Response.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public Response ensureResponseCodeIsNotError() throws HttpResponseException {
119119
*/
120120
public Response ensureResponseCodeInRange(final int min, final int max)
121121
throws HttpResponseException {
122+
if (min > max) throw new IllegalArgumentException("min must be less than max");
122123
if (responseCode() < min || responseCode() > max) {
123124
throw new HttpResponseException(this);
124125
}
@@ -131,7 +132,7 @@ public Response ensureResponseCodeNotInRange(
131132
final Function<Response, HttpResponseException> errorSupplier
132133
)
133134
throws HttpResponseException {
134-
if (min > max) throw new RuntimeException("min must be less than max");
135+
if (min > max) throw new IllegalArgumentException("min must be less than max");
135136
if (responseCode() >= min && responseCode() <= max) {
136137
throw errorSupplier.apply(this);
137138
}
@@ -168,7 +169,7 @@ public Response throwIfClientError()
168169
/**
169170
* Throw exception if response code is a 5xx server error
170171
* @return this {@code Response}
171-
* @throws HttpResponseException if the response code is 4xx
172+
* @throws HttpResponseException if the response code is 5xx
172173
*/
173174
public Response throwIfServerError(
174175
final Function<Response, HttpResponseException> errorSupplier
@@ -177,6 +178,11 @@ public Response throwIfServerError(
177178
return throwIfResponseCodeInRange(500, 599, errorSupplier);
178179
}
179180

181+
/**
182+
* Throw exception if response code is a 5xx server error
183+
* @return this {@code Response}
184+
* @throws HttpResponseException if the response code is 5xx
185+
*/
180186
public Response throwIfServerError()
181187
throws HttpResponseException {
182188
return throwIfServerError(HttpResponseException::new);

0 commit comments

Comments
 (0)