From e8942b264576360dd8007cc865c6f8a6ceb87c29 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Sat, 4 Oct 2025 12:11:13 +0800 Subject: [PATCH] fix --- conf/views.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/conf/views.py b/conf/views.py index 788a6bd..ff24804 100644 --- a/conf/views.py +++ b/conf/views.py @@ -310,8 +310,11 @@ class RandomUsernameAPI(APIView): class HitokotoAPI(APIView): def get(self, request): - categories = JsonDataLoader.load_data(settings.HITOKOTO_DIR, "categories.json") - path = random.choice(categories).get("path") - sentences = JsonDataLoader.load_data(settings.HITOKOTO_DIR, path) - sentence = random.choice(sentences) - return self.success(sentence) + try: + categories = JsonDataLoader.load_data(settings.HITOKOTO_DIR, "categories.json") + path = random.choice(categories).get("path") + sentences = JsonDataLoader.load_data(settings.HITOKOTO_DIR, path) + sentence = random.choice(sentences) + return self.success(sentence) + except Exception: + return self.error("获取一言失败,请稍后再试")