fix(error): URLUtil 异常不再吞没,改为抛出 IllegalArgumentException

原代码 catch Exception 后仅打印堆栈,调用方无法感知解析失败。
改为抛出 IllegalArgumentException,让调用方明确知道 URL 解析失败。
This commit is contained in:
yukaidi
2026-05-29 00:33:10 +08:00
parent 85fe910f25
commit 0dfee8ab22

View File

@@ -24,14 +24,17 @@ public class URLUtil {
if (query != null) {
String[] pairs = query.split("&");
for (String pair : pairs) {
String[] keyValue = pair.split("=");
if (pair == null || pair.isEmpty()) {
continue;
}
String[] keyValue = pair.split("=", 2);
String key = URLDecoder.decode(keyValue[0], StandardCharsets.UTF_8);
String value = keyValue.length > 1 ? URLDecoder.decode(keyValue[1], StandardCharsets.UTF_8) : "";
queryParams.put(key, value);
}
}
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException("URL解析失败: " + url, e);
}
}