【问题标题】:Why does retrofit throw an exception before Observable is created?为什么改造在 Observable 创建之前会抛出异常?
【发布时间】:2016-08-25 23:20:48
【问题描述】:

我正在测试无法访问互联网的边缘案例。 当我打电话时

Observable<SomeResponse> responseObservable = client.getMethodNameRedacted("string");

Retrofit 在拦截器内部的请求链中进行时抛出以下错误:

V/CustomLoggingInterceptor$Logger: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "{redacted}": No address associated with hostname

所以我无法处理 observable 中的错误。

有什么方法可以封装 observable 来处理这个错误吗?

编辑: 日志拦截器只是一个稍作修改的 OkHttpLoggingInterceptor,用于按内容类型过滤日志。它根本不会影响请求链。

【问题讨论】:

    标签: retrofit rx-java retrofit2 rx-android


    【解决方案1】:

    将响应对象包装在实际的响应对象中工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多