I recently encountered a problem using "RxJava2" plus "Retrofit2".
I will return to the server results through a "Map", but you know, the server isn't always return a valid data, sometimes he will return "null" to me, but if I by "return" to a "Map" conversion "null", will throw an exception
com.qian.qianlibrary.http.rx_http.exception.ApiException: java.lang.NullPointerException: The mapper function returned a null value.
So can I do another way to return "null" to my server without throwing any exceptions?
public class HttpResultFunction<T> implements Function<Throwable, Observable<T>> {
@Override
public Observable<T> apply(@NonNull Throwable throwable) throws Exception {
Logger.e("HttpResultFunction:" + throwable);
return Observable.error(ExceptionEngine.handleException(throwable));
}
}
public class ServerResultFunction implements Function<HttpResponse, Object> {
@Override
public Object apply(@NonNull HttpResponse response) throws Exception {
Logger.i(response.toString());
if (!response.isSuccess()) {
throw new ServerException(response.getCode(), response.getMsg());
}
// "response. getResult ()" might be a "null",It is an "Object"
return response.getResult();
}
version number
my question
I recently encountered a problem using "RxJava2" plus "Retrofit2". I will return to the server results through a "Map", but you know, the server isn't always return a valid data, sometimes he will return "null" to me, but if I by "return" to a "Map" conversion "null", will throw an exception
com.qian.qianlibrary.http.rx_http.exception.ApiException: java.lang.NullPointerException: The mapper function returned a null value.
So can I do another way to return "null" to my server without throwing any exceptions?This is my source code.