本文整理了Java中rx.Observable.error()
方法的一些代码示例,展示了Observable.error()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.error()
方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:error
[英]Returns an Observable that invokes an Observer's Observer#onError method when the Observer subscribes to it.
Scheduler: error does not operate by default on a particular Scheduler.
[中]返回一个Observable,当观察者订阅它时,它调用观察者的Observator#onError方法。
计划程序:默认情况下,错误不会在特定计划程序上运行。
代码示例来源:origin: greenrobot/greenDAO
@Override
public Observable<T> call() {
T result;
try {
result = callable.call();
} catch (Exception e) {
return Observable.error(e);
}
return Observable.just(result);
}
});
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<PolicySetDefinitionInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<PolicySetDefinitionInner>> result = listBuiltInDelegate(response);
return Observable.just(new ServiceResponse<Page<PolicySetDefinitionInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<ProviderInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<ProviderInner>> result = listNextDelegate(response);
return Observable.just(new ServiceResponse<Page<ProviderInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: PipelineAI/pipeline
@Override
public Observable<R> call() {
try {
return Observable.just(getFallback());
} catch (Throwable ex) {
return Observable.error(ex);
}
}
});
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<TenantIdDescriptionInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl1<TenantIdDescriptionInner>> result = listNextDelegate(response);
return Observable.just(new ServiceResponse<Page<TenantIdDescriptionInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: hidroh/materialistic
private Observable<Response> execute(Request request) {
return Observable.defer(() -> {
try {
return Observable.just(mCallFactory.newCall(request).execute());
} catch (IOException e) {
return Observable.error(e);
}
}).subscribeOn(mIoScheduler);
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<FeatureResultInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<FeatureResultInner>> result = list1Delegate(response);
return Observable.just(new ServiceResponse<Page<FeatureResultInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: hidroh/materialistic
@Override
public void login(String username, String password, boolean createAccount, Callback callback) {
execute(postLogin(username, password, createAccount))
.flatMap(response -> {
if (response.code() == HttpURLConnection.HTTP_OK) {
return Observable.error(new UserServices.Exception(parseLoginError(response)));
}
return Observable.just(response.code() == HttpURLConnection.HTTP_MOVED_TEMP);
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(callback::onDone, callback::onError);
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<TagDetailsInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<TagDetailsInner>> result = listNextDelegate(response);
return Observable.just(new ServiceResponse<Page<TagDetailsInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: PipelineAI/pipeline
@Override
protected Observable<Boolean> resumeWithFallback() {
if (fallbackBehavior == FALLBACK_SUCCESS) {
return Observable.just(false);
} else if (fallbackBehavior == FALLBACK_FAILURE) {
RuntimeException ex = new RuntimeException("fallback failure");
if (asyncFallbackException) {
return Observable.error(ex);
} else {
throw ex;
}
} else { //FALLBACK_NOT_IMPLEMENTED
return super.resumeWithFallback();
}
}
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<DeploymentOperationInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<DeploymentOperationInner>> result = listByResourceGroupDelegate(response);
return Observable.just(new ServiceResponse<Page<DeploymentOperationInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: hidroh/materialistic
Observable.just(response) :
Observable.error(new IOException()))
.flatMap(response -> {
try {
return Observable.just(new String[]{
response.header(HEADER_SET_COOKIE),
response.body().string()
});
} catch (IOException e) {
return Observable.error(e);
} finally {
response.close();
})
.flatMap(array -> !TextUtils.isEmpty(array[1]) ?
Observable.just(array) :
Observable.error(new IOException()))
.flatMap(array -> execute(postSubmit(title, content, isUrl, array[0], array[1])))
.flatMap(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP ?
Observable.just(Uri.parse(response.header(HEADER_LOCATION))) :
Observable.error(new IOException()))
.flatMap(uri -> TextUtils.equals(uri.getPath(), DEFAULT_SUBMIT_REDIRECT) ?
Observable.just(true) :
Observable.error(buildException(uri)))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(callback::onDone, callback::onError);
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<DeploymentOperationInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<DeploymentOperationInner>> result = listByResourceGroupNextDelegate(response);
return Observable.just(new ServiceResponse<Page<DeploymentOperationInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: PipelineAI/pipeline
@Override
protected Observable<Integer> construct() {
return Observable.just(1, 2, 3)
.concatWith(Observable.<Integer> error(new RuntimeException("forced error")))
.subscribeOn(Schedulers.computation());
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<GenericResourceInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<GenericResourceInner>> result = listByResourceGroupNextDelegate(response);
return Observable.just(new ServiceResponse<Page<GenericResourceInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: PipelineAI/pipeline
@Override
protected Observable<Boolean> construct() {
return Observable.just(false, true, false)
.concatWith(Observable.<Boolean>error(new RuntimeException("forced error")))
.subscribeOn(Schedulers.computation());
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<PolicyAssignmentInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl<PolicyAssignmentInner>> result = listByResourceGroupDelegate(response);
return Observable.just(new ServiceResponse<Page<PolicyAssignmentInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: PipelineAI/pipeline
@HystrixCommand(
commandKey = COMMAND_KEY,
ignoreExceptions = {
BadRequestException.class,
NotFoundException.class
},
fallbackMethod = "fallback")
public Observable<User> getUserById(String id) throws NotFoundException {
validate(id);
if (!USERS.containsKey(id)) {
return Observable.error(new NotFoundException("user with id: " + id + " not found"));
}
return Observable.just(USERS.get(id));
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Observable<ServiceResponse<Page<SubscriptionInner>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl1<SubscriptionInner>> result = listDelegate(response);
return Observable.just(new ServiceResponse<Page<SubscriptionInner>>(result.body(), result.response()));
} catch (Throwable t) {
return Observable.error(t);
}
}
});
代码示例来源:origin: hidroh/materialistic
@Test
public void testGetItemForceCacheUnsatisfiable() {
when(TestRestServiceFactory.hnRestService.cachedItemRx(eq("1")))
.thenReturn(Observable.error(new IOException()));
when(TestRestServiceFactory.hnRestService.itemRx(eq("1")))
.thenReturn(Observable.just(mock(HackerNewsItem.class)));
client.getItem("1", ItemManager.MODE_CACHE, itemListener);
verify(TestRestServiceFactory.hnRestService).cachedItemRx(eq("1"));
verify(TestRestServiceFactory.hnRestService).itemRx(eq("1"));
}
内容来源于网络,如有侵权,请联系作者删除!