I'm using Koush Ion library, and I want to know if there is an option to throw an exception if the response code is not 20x (like if it's 400, 401 etc).
Asked
Active
Viewed 74 times
1 Answers
0
You can simply check for the ".code()" in the response headers.
While building the Ion request, make sure you add the ".withResponse()"
Ion.with(getContext())
.load("http://example.com/test.txt")
.asString()
.withResponse()
.setCallback(new FutureCallback<Response<String>>() {
@Override
public void onCompleted(Exception e, Response<String> result) {
// print the response code, ie, 200
System.out.println(result.getHeaders().code());
// print the String that was downloaded
System.out.println(result.getResult());
}
});
Based on the code() response, you can manually throw the exception.

Ashwin Valento
- 878
- 1
- 7
- 14