Переглянути джерело

修复NoCacheException无法捕获

drake 2 роки тому
батько
коміт
565860bc25

+ 7 - 1
net/src/main/java/com/drake/net/exception/NoCacheException.kt

@@ -1,5 +1,6 @@
 package com.drake.net.exception
 
+import com.drake.net.cache.ForceCache
 import okhttp3.Request
 
 /**
@@ -13,4 +14,9 @@ class NoCacheException(
     request: Request,
     message: String? = null,
     cause: Throwable? = null
-) : NetException(request, message, cause)
+) : NetException(request, message, cause) {
+
+    override fun getLocalizedMessage(): String {
+        return "cacheKey = " + ForceCache.key(request) + " " + super.getLocalizedMessage()
+    }
+}

+ 2 - 0
net/src/main/java/com/drake/net/interceptor/NetOkHttpInterceptor.kt

@@ -77,6 +77,8 @@ object NetOkHttpInterceptor : Interceptor {
             } else {
                 throw NetworkingException(request)
             }
+        } catch (e: NetException) {
+            throw e
         } catch (e: Throwable) {
             throw HttpFailureException(request, cause = e)
         }