我想知道什麼是與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)?