Browse Source

feat: 优化转换器ConvertException错误信息

drake 1 năm trước cách đây
mục cha
commit
10c691eb7f

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

@@ -71,9 +71,10 @@ abstract class JSONConvert(
                         bodyString.parseBody<R>(succeed)
                     }
                 }
+
                 code in 400..499 -> throw RequestParamsException(response, code.toString()) // 请求参数错误
                 code >= 500 -> throw ServerResponseException(response, code.toString()) // 服务器异常错误
-                else -> throw ConvertException(response)
+                else -> throw ConvertException(response, message = "Http status code not within range")
             }
         }
     }

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

@@ -166,7 +166,7 @@ inline fun <reified R> Response.convert(): R {
     } catch (e: NetException) {
         throw e
     } catch (e: Throwable) {
-        throw ConvertException(this, cause = e)
+        throw ConvertException(this, message = "An unexpected error occurred in the converter", cause = e)
     }
 }
 
@@ -185,6 +185,6 @@ fun <R> Response.convert(type: Type): R {
     } catch (e: NetException) {
         throw e
     } catch (e: Throwable) {
-        throw ConvertException(this, cause = e)
+        throw ConvertException(this, message = "An unexpected error occurred in the converter", cause = e)
     }
 }

+ 1 - 1
sample/src/main/java/com/drake/net/sample/converter/ProtobufConverter.kt

@@ -27,7 +27,7 @@ class ProtobufConverter : NetConverter {
                 }
                 code in 400..499 -> throw RequestParamsException(response, code.toString()) // 请求参数错误
                 code >= 500 -> throw ServerResponseException(response, code.toString()) // 服务器异常错误
-                else -> throw ConvertException(response)
+                else -> throw ConvertException(response, message = "Http status code not within range")
             }
         }
     }

+ 2 - 1
sample/src/main/java/com/drake/net/sample/converter/SerializationConverter.kt

@@ -53,9 +53,10 @@ class SerializationConverter(
                         bodyString.parseBody<R>(kType)
                     }
                 }
+
                 code in 400..499 -> throw RequestParamsException(response, code.toString()) // 请求参数错误
                 code >= 500 -> throw ServerResponseException(response, code.toString()) // 服务器异常错误
-                else -> throw ConvertException(response)
+                else -> throw ConvertException(response, message = "Http status code not within range")
             }
         }
     }