liujingxing / rxhttp

🔥🔥🔥 Based on OkHttp encapsulation, support Kotlin Coroutines、RxJava2、RxJava3; 30s to get started.
https://juejin.im/post/5ded221a518825125d14a1d4
Apache License 2.0
3.74k stars 457 forks source link

有时候后台会返回一些意想不到的json #485

Closed GXSZone closed 7 months ago

GXSZone commented 7 months ago

转换错误直接就嘎了,建议写个兜底策略

Tunnel suiy25.natappfree.cc not found
12:17:25.180 RxHttp                   E  rxhttp.wrapper.exception.HttpStatusCodeException: http/1.0 404 Not Found, http://suiy25.natappfree.cc/user/v1/phone/send
12:17:25.180 RxHttp                   E     at rxhttp.wrapper.OkHttpCompat.throwIfFail(OkHttpCompat.java:122)
12:17:25.180 RxHttp                   E     at rxhttp.wrapper.utils.Converter.convert(Converter.java:33)
12:17:25.180 RxHttp                   E     at rxhttp.wrapper.parse.SmartParser.onParse(SmartParser.java:27)
12:17:25.180 RxHttp                   E     at rxhttp.wrapper.utils.Utils$await$2$2.onResponse(Utils.kt:37)
12:17:25.180 RxHttp                   E     at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
12:17:25.180 RxHttp                   E     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
12:17:25.180 RxHttp                   E     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
12:17:25.180 RxHttp                   E     at java.lang.Thread.run(Thread.java:1012)
12:17:25.196 DEBUG                    E  encryptLog: false, zipCrashLog: false
12:17:25.196 DEBUG                    E  begin to generate java report
12:17:25.201 DEBUG                    E  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12:17:25.201 DEBUG                    E  Basic Information: 'pid: 6266/tid: 6266/time: 20240211121725'
liujingxing commented 7 months ago

这么早就开工了吗?只要出现异常,都会走异常回调,再一个,你这也不是啥转换错误,你接口404了

GXSZone commented 7 months ago

这么早就开工了吗?只要出现异常,都会走异常回调,再一个,你这也不是啥转换错误,你接口404了

没事自己业余写写,就是因为接口404就蹦了

liujingxing commented 7 months ago

你需要自己设置一个异常回调

GXSZone commented 7 months ago

你需要自己设置一个异常回调

他是直接崩了,回调也拦不住啊

liujingxing commented 7 months ago

不会的,提供下代码

GXSZone commented 7 months ago

image try一下就捕获异常了

GXSZone commented 7 months ago

应该是我代码问题吧,其他的404也没事

GXSZone commented 7 months ago

image

GXSZone commented 7 months ago

image 这就没问题

liujingxing commented 7 months ago

有一系列await方法,可以捕获异常,不需要自己写try语句。如tryAwait、awaitResult方法

GXSZone commented 7 months ago

刚又看了下文档,很方便