drake vor 3 Jahren
Ursprung
Commit
f33ebb20fd

+ 1 - 1
net/src/main/java/com/drake/net/convert/NetConverter.kt

@@ -47,7 +47,7 @@ interface NetConverter {
                     ByteArray::class.java -> response.body?.bytes() as R
                     ByteArray::class.java -> response.body?.bytes() as R
                     Response::class.java -> response as R
                     Response::class.java -> response as R
                     File::class.java -> response.file() as R
                     File::class.java -> response.file() as R
-                    else -> throw ConvertException(response, "The default converter does not support this type")
+                    else -> throw ConvertException(response, "An exception occurred while converting the NetConverter.DEFAULT")
                 }
                 }
             }
             }
         }
         }

+ 2 - 2
net/src/main/java/com/drake/net/exception/ConvertException.kt

@@ -23,6 +23,6 @@ import okhttp3.Response
  */
  */
 class ConvertException(
 class ConvertException(
     val response: Response,
     val response: Response,
-    info: String = "An exception occurred while converting the data",
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(response.request, info, cause)
+) : NetException(response.request, message, cause)

+ 2 - 2
net/src/main/java/com/drake/net/exception/DownloadFileException.kt

@@ -7,6 +7,6 @@ import okhttp3.Response
  */
  */
 class DownloadFileException(
 class DownloadFileException(
     response: Response,
     response: Response,
-    info: String? = null,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(response.request, info, cause)
+) : NetException(response.request, message, cause)

+ 4 - 2
net/src/main/java/com/drake/net/exception/NetCancellationException.kt

@@ -24,8 +24,10 @@ import java.util.concurrent.CancellationException
 /**
 /**
  * 取消网络任务的异常
  * 取消网络任务的异常
  */
  */
-class NetCancellationException(coroutineScope: CoroutineScope, message: String? = null) :
-    CancellationException(message) {
+class NetCancellationException(
+    coroutineScope: CoroutineScope,
+    message: String? = null,
+) : CancellationException(message) {
     init {
     init {
         Net.cancelGroup(coroutineScope.coroutineContext[CoroutineExceptionHandler])
         Net.cancelGroup(coroutineScope.coroutineContext[CoroutineExceptionHandler])
     }
     }

+ 2 - 1
net/src/main/java/com/drake/net/exception/NetConnectException.kt

@@ -4,5 +4,6 @@ import okhttp3.Request
 
 
 class NetConnectException(
 class NetConnectException(
     request: Request,
     request: Request,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(request, cause = cause)
+) : NetException(request, message, cause)

+ 4 - 4
net/src/main/java/com/drake/net/exception/NetException.kt

@@ -24,15 +24,15 @@ import java.io.IOException
  * Net网络异常
  * Net网络异常
  *
  *
  * @param request 请求信息
  * @param request 请求信息
- * @param info 异常信息
+ * @param message 异常信息
  */
  */
 open class NetException(
 open class NetException(
     val request: Request,
     val request: Request,
-    val info: String? = null,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : IOException(cause) {
+) : IOException(message, cause) {
 
 
     override fun getLocalizedMessage(): String? {
     override fun getLocalizedMessage(): String? {
-        return info?.let { "$it [${request.url}]" } ?: "[${request.url}]"
+        return if (message == null) "$message (${request.url})" else "(${request.url})"
     }
     }
 }
 }

+ 2 - 2
net/src/main/java/com/drake/net/exception/NetSocketTimeoutException.kt

@@ -4,6 +4,6 @@ import okhttp3.Request
 
 
 class NetSocketTimeoutException(
 class NetSocketTimeoutException(
     request: Request,
     request: Request,
-    info: String? = null,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(request, info, cause)
+) : NetException(request, message, cause)

+ 2 - 1
net/src/main/java/com/drake/net/exception/NetUnknownHostException.kt

@@ -4,5 +4,6 @@ import okhttp3.Request
 
 
 class NetUnknownHostException(
 class NetUnknownHostException(
     request: Request,
     request: Request,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(request, cause = cause)
+) : NetException(request, message, cause)

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

@@ -4,6 +4,6 @@ import okhttp3.Request
 
 
 class NoCacheException(
 class NoCacheException(
     request: Request,
     request: Request,
-    info: String? = null,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : NetException(request, info, cause)
+) : NetException(request, message, cause)

+ 4 - 1
net/src/main/java/com/drake/net/exception/RequestParamsException.kt

@@ -21,4 +21,7 @@ import okhttp3.Response
 /**
 /**
  * 400 - 499 客户端请求异常
  * 400 - 499 客户端请求异常
  */
  */
-class RequestParamsException(val response: Response) : NetException(response.request)
+class RequestParamsException(
+    val response: Response,
+    message: String? = null
+) : NetException(response.request, message)

+ 2 - 2
net/src/main/java/com/drake/net/exception/ResponseException.kt

@@ -25,5 +25,5 @@ import okhttp3.Response
  */
  */
 class ResponseException(
 class ResponseException(
     response: Response,
     response: Response,
-    info: String?
-) : NetException(response.request, info)
+    message: String? = null
+) : NetException(response.request, message)

+ 4 - 1
net/src/main/java/com/drake/net/exception/ServerResponseException.kt

@@ -22,4 +22,7 @@ import okhttp3.Response
 /**
 /**
  * >= 500 服务器异常
  * >= 500 服务器异常
  */
  */
-class ServerResponseException(val response: Response) : NetException(response.request)
+class ServerResponseException(
+    val response: Response,
+    message: String? = null,
+) : NetException(response.request, message)

+ 2 - 2
net/src/main/java/com/drake/net/exception/URLParseException.kt

@@ -4,6 +4,6 @@ package com.drake.net.exception
  * URL地址错误
  * URL地址错误
  */
  */
 open class URLParseException(
 open class URLParseException(
-    val url: String,
+    message: String? = null,
     cause: Throwable? = null
     cause: Throwable? = null
-) : Exception(url, cause)
+) : Exception(message, cause)

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

@@ -38,7 +38,7 @@ object NetOkHttpInterceptor : Interceptor {
         } catch (e: ConnectException) {
         } catch (e: ConnectException) {
             throw NetConnectException(request, cause = e)
             throw NetConnectException(request, cause = e)
         } catch (e: UnknownHostException) {
         } catch (e: UnknownHostException) {
-            throw NetUnknownHostException(request, e)
+            throw NetUnknownHostException(request, cause = e)
         } catch (e: Throwable) {
         } catch (e: Throwable) {
             throw NetException(request, cause = e)
             throw NetException(request, cause = e)
         }
         }

+ 1 - 1
net/src/main/java/com/drake/net/request/RequestExtension.kt

@@ -186,6 +186,6 @@ fun Request.logString(byteCount: Long = 1024 * 1024): String? {
     return if (body is FormBody || mediaType.type == "text" || mediaType.subtype == "json") {
     return if (body is FormBody || mediaType.type == "text" || mediaType.subtype == "json") {
         body?.peekString(byteCount)
         body?.peekString(byteCount)
     } else {
     } else {
-        "LogRecordInterceptor not support this type $mediaType"
+        "Not support this type $mediaType"
     }
     }
 }
 }

+ 2 - 2
net/src/main/java/com/drake/net/response/ResponseExtention.kt

@@ -108,7 +108,7 @@ fun Response.file(): File? {
         if (request.downloadTempFile()) file.delete()
         if (request.downloadTempFile()) file.delete()
         throw CancellationException(e)
         throw CancellationException(e)
     } catch (e: Exception) {
     } catch (e: Exception) {
-        throw DownloadFileException(this, "An exception occurred while download file", e)
+        throw DownloadFileException(this, cause = e)
     }
     }
 }
 }
 
 
@@ -121,6 +121,6 @@ fun Response.logString(byteCount: Long = 1024 * 1024 * 4): String? {
     return if (mediaType.subtype == "json" || mediaType.type == "text") {
     return if (mediaType.subtype == "json" || mediaType.type == "text") {
         body?.peekString(byteCount)
         body?.peekString(byteCount)
     } else {
     } else {
-        "LogRecordInterceptor not support this type $mediaType"
+        "Not support this type $mediaType"
     }
     }
 }
 }