Skip to content

Commit 5abaa24

Browse files
Fix #905: Handle invalid Hardcover tokens gracefully
Treat 401 Unauthorized responses from Hardcover API as missing/invalid tokens instead of raising generic exceptions. This prevents error logs when users don't have valid Hardcover API tokens and ensures proper handling via the existing MissingHardcoverToken exception flow. The fix allows users without Hardcover tokens to sync their Kobo devices without generating ERROR-level log entries, logging an informational message instead.
1 parent fa2f2f7 commit 5abaa24

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

cps/services/hardcover.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ def execute(self, query, variables=None):
526526
try:
527527
response.raise_for_status()
528528
except requests.exceptions.HTTPError as e:
529+
# 401 Unauthorized means invalid/missing token - treat as missing token
530+
if response.status_code == 401:
531+
raise MissingHardcoverToken("Invalid or expired Hardcover API token")
529532
raise Exception(f"HTTP error occurred: {e}")
530533
result = response.json()
531534
if "errors" in result:

0 commit comments

Comments
 (0)