From 8171137b8c1b8e6873f52dfdb23b100459c28209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=9D=E4=B8=8D=E7=AD=89=E7=90=B4=E7=94=9F?= <39022409+zhicheng-ning@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:41:54 +0800 Subject: [PATCH] fix: add exception handling (#41) --- src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java b/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java index 520b3e6..636eeee 100644 --- a/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java +++ b/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java @@ -117,7 +117,13 @@ public Set parseRepo(String url) throws IOException { public Set parseRepo(String url, int count) throws IOException { JSONObject jsonObject = NetUtil.doGet(url); Set repoNames = new HashSet<>(); - JSONArray jsonArray = jsonObject.getJSONArray("data"); + JSONArray jsonArray = null; + try { + jsonArray = jsonObject.getJSONArray("data"); + } catch (Exception e) { + e.printStackTrace(); + return repoNames; + } int cnt = 0; for (int i = 0; i < jsonArray.size(); i++) { String repoName = jsonArray.getJSONObject(i).getJSONObject("item").getString("name");