我想知道什么是与RxJava和春季REST API最好?RxJava自定义异常处理/传播在春季启动休息应用程序
我有一个简单的REST服务,并在存储库中,如果有错误,我想传播一个特定的自定义错误到客户端。但我不知道如何映射不同的自定义异常与RxJava。
这里是到后端的呼叫:
private Single<Customer> findCustomerById(long customerId) {
return Single.fromCallable(() -> getRestTemplate().getForObject(
MyBackendService.SEARCH_CUSTOMER_BY_ID.getUrl(),
Customer.class, customerId))
.onErrorResumeNext(ex -> Single.error(new BackendException(ex)));
}
我的例外:
public class BackendException extends Exception {
public BackendException(String message) {
super(message);
}
public BackendException(Throwable cause) {
super(cause);
}
所以,问题是如何映射/与传播RxJava这BackendException
让我们说NotFound
(404 )或InternalServerError
(500)?