Skip to content

Commit ffa198e

Browse files
committed
Assert Throwable instance of HttpException
1 parent 5d0907f commit ffa198e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

errorhandler-matchers/retrofit-rx-matcher/src/main/java/com/workable/errorhandler/matchers/retrofit/RetrofitMatcherFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import retrofit2.adapter.rxjava.HttpException;
66

77

8+
89
public class RetrofitMatcherFactory {
910

1011
private RetrofitMatcherFactory() {
@@ -20,7 +21,8 @@ public static MatcherFactory<Integer> create() {
2021
public Matcher build(final Integer httpStatusCode) {
2122
return new Matcher() {
2223
public boolean matches(Throwable throwable) {
23-
return ((HttpException) throwable).code() == httpStatusCode;
24+
return throwable instanceof HttpException &&
25+
((HttpException) throwable).code() == httpStatusCode;
2426
}
2527
};
2628
}
@@ -36,8 +38,8 @@ public static MatcherFactory<Range> createRange() {
3638
public Matcher build(final Range range) {
3739
return new Matcher() {
3840
public boolean matches(Throwable throwable) {
39-
HttpException httpException = (HttpException)throwable;
40-
return range.contains(httpException.code());
41+
return throwable instanceof HttpException &&
42+
range.contains(((HttpException)throwable).code());
4143
}
4244
};
4345
}

0 commit comments

Comments
 (0)