From 4b04659fce7348ec1fd0f67d1af8178bf1afd631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Wed, 1 Apr 2026 04:32:42 +0200 Subject: [PATCH] Add error handling for HTTP requests in import_chzzk_campaign command and enhance pagination display in campaign list template --- chzzk/management/commands/import_chzzk_campaign.py | 12 +++++++++++- templates/chzzk/campaign_list.html | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/chzzk/management/commands/import_chzzk_campaign.py b/chzzk/management/commands/import_chzzk_campaign.py index 484dd66..6288923 100644 --- a/chzzk/management/commands/import_chzzk_campaign.py +++ b/chzzk/management/commands/import_chzzk_campaign.py @@ -52,7 +52,17 @@ class Command(BaseCommand): "User-Agent": USER_AGENT, }, ) - resp.raise_for_status() + try: + resp.raise_for_status() + except requests.HTTPError as e: + json_msg: str = "" + if resp.headers.get("Content-Type", "").startswith("application/json"): + error_data = resp.json() + json_msg = error_data.get("message", "") + + msg: str = f"Failed to fetch campaign {campaign_no}: {e} - {json_msg}" + self.stdout.write(self.style.ERROR(msg)) + return data: dict[str, Any] = resp.json() campaign_data: ChzzkCampaignV2 diff --git a/templates/chzzk/campaign_list.html b/templates/chzzk/campaign_list.html index 04b9025..bede94f 100644 --- a/templates/chzzk/campaign_list.html +++ b/templates/chzzk/campaign_list.html @@ -47,7 +47,11 @@ {% if is_paginated %} - {% include "includes/pagination.html" with page_obj=page_obj %} + {% endif %} {% else %}

No campaigns found.