From 3d6859b865c8ea7b4709cd9572a4d05d1e2f0dde Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Wed, 11 Jun 2025 03:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(controller):=20gracefully=20ha?= =?UTF-8?q?ndle=20missing=20Uptime=20Kuma=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the uptime status endpoint returned HTTP 400 with “未配置 Uptime Kuma URL/Slug” when either option was not set, resulting in frontend error states. Changes: • Treat absence of `UptimeKumaUrl` or `UptimeKumaSlug` as a valid scenario. • Immediately respond with HTTP 200, `success: true`, and an empty `data` array. • Preserve existing behavior when both options are provided. This prevents unnecessary error notifications on the dashboard when Uptime Kuma integration is not configured and improves overall UX. --- controller/uptime_kuma.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/controller/uptime_kuma.go b/controller/uptime_kuma.go index 245cac3f..6ceaa1f3 100644 --- a/controller/uptime_kuma.go +++ b/controller/uptime_kuma.go @@ -82,18 +82,11 @@ func GetUptimeKumaStatus(c *gin.Context) { slug := common.OptionMap["UptimeKumaSlug"] common.OptionMapRWMutex.RUnlock() - if uptimeKumaUrl == "" { - c.JSON(http.StatusBadRequest, gin.H{ - "success": false, - "message": "未配置 Uptime Kuma URL", - }) - return - } - - if slug == "" { - c.JSON(http.StatusBadRequest, gin.H{ - "success": false, - "message": "未配置 Uptime Kuma Slug", + if uptimeKumaUrl == "" || slug == "" { + c.JSON(http.StatusOK, gin.H{ + "success": true, + "message": "", + "data": []MonitorStatus{}, }) return }