From 186b4c3265dbdf216e2c82658f821c012499ccf2 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Sun, 8 Sep 2024 10:41:02 +0800 Subject: [PATCH] Handle `sql.ErrNoRows` in `CheckModelAccess` and respond with error message. --- api/chat_main_handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/chat_main_handler.go b/api/chat_main_handler.go index d77591e2..f7fd8654 100644 --- a/api/chat_main_handler.go +++ b/api/chat_main_handler.go @@ -437,6 +437,16 @@ func (h *ChatHandler) CheckModelAccess(w http.ResponseWriter, chatSessionUuid st Model: rate.ChatModelName, }) + if err != nil { + // no rows + if errors.Is(err, sql.ErrNoRows) { + RespondWithError(w, http.StatusInternalServerError, "error.fail_to_get_rate_limit", err) + return true + } + RespondWithError(w, http.StatusInternalServerError, "error.fail_to_get_rate_limit", err) + return true + } + log.Printf("%+v", usage10Min) if int32(usage10Min) > rate.RateLimit {