Add error handling for HTTP requests in import_chzzk_campaign command and enhance pagination display in campaign list template
All checks were successful
Deploy to Server / deploy (push) Successful in 21s
All checks were successful
Deploy to Server / deploy (push) Successful in 21s
This commit is contained in:
parent
a0aef85b32
commit
4b04659fce
2 changed files with 16 additions and 2 deletions
|
|
@ -52,7 +52,17 @@ class Command(BaseCommand):
|
||||||
"User-Agent": USER_AGENT,
|
"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()
|
data: dict[str, Any] = resp.json()
|
||||||
|
|
||||||
campaign_data: ChzzkCampaignV2
|
campaign_data: ChzzkCampaignV2
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,11 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% include "includes/pagination.html" with page_obj=page_obj %}
|
<div class="pagination">
|
||||||
|
{% if page_obj.has_previous %}<a href="?page={{ page_obj.previous_page_number }}">Previous</a>{% endif %}
|
||||||
|
<span>Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>
|
||||||
|
{% if page_obj.has_next %}<a href="?page={{ page_obj.next_page_number }}">Next</a>{% endif %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No campaigns found.</p>
|
<p>No campaigns found.</p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue