我正在使用Retrofit2和RxJava2向后端服务器提出请求。当响应为200或201时,一切正常。当服务器的响应是409或503并且抛出一个HttpException时,它不会被可观察到的onError()捕获,应用程序也会崩溃。
我提出的要求如下:
@POST("users/sign-up")
fun register(@Body register: RegisterBody): Observable<User>我提出请求的代码片段如下(applySchedulers()只应用subscribeOn()和observeOn()):
api.register(body)
.compose(applySchedulers())
.subscribe(
{ user -> onNextRegister(user.id, email.toString(), password.toString()) },
{ error -> handleRegistrationError(error) })引发的异常如下:
io.reactivex.exceptions.CompositeException: 2 exceptions occurred.
ComposedException 1 : retrofit2.adapter.rxjava2.HttpException: HTTP 503 Unavailable
ComposedException 2 : kotlin.NotImplementedError: An operation is not implemented: not implemented即使我为可观察到的应用程序实现了onError(),我如何防止应用程序崩溃呢?请注意,来自handleRegistrationError(error)的代码仍然被执行。
发布于 2017-10-13 10:29:27
CompositeException表示实际问题在handleRegistrationError(error)中。不知怎么你做了什么导致
kotlin.NotImplementedError: An operation is not implemented: not implemented很可能它与您作为TODO()实现的函数相关。
fun TODO(): Nothing = throw NotImplementedError()因此,只要实现这一点(或删除TODO()),您可能会解决问题。
https://stackoverflow.com/questions/46727497
复制相似问题