Skip to content

Commit

Permalink
fix C901
Browse files Browse the repository at this point in the history
  • Loading branch information
jahwag committed Aug 19, 2024
1 parent 1e47650 commit 7575f8c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/claudesync/providers/claude_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,29 @@ def _make_request(self, method, endpoint, data=None):
return json.loads(content_str)

except urllib.error.HTTPError as e:
self.logger.error(f"Request failed: {str(e)}")
self.logger.error(f"Response status code: {e.code}")
self.logger.error(f"Response headers: {e.headers}")
content = e.read().decode("utf-8")
self.logger.error(f"Response content: {content}")

if e.code == 403:
error_msg = (
"Received a 403 Forbidden error. Your session key might be invalid. "
"Please try logging out and logging in again. If the issue persists, "
"you can try using the claude.ai-curl provider as a workaround:\n"
"claudesync api logout\n"
"claudesync api login claude.ai-curl"
)
self.logger.error(error_msg)
raise ProviderError(error_msg)

raise ProviderError(f"API request failed: {str(e)}")
self.handle_http_error(e)
except urllib.error.URLError as e:
self.logger.error(f"URL Error: {str(e)}")
raise ProviderError(f"API request failed: {str(e)}")
except json.JSONDecodeError as json_err:
self.logger.error(f"Failed to parse JSON response: {str(json_err)}")
self.logger.error(f"Response content: {content_str}")
raise ProviderError(f"Invalid JSON response from API: {str(json_err)}")

def handle_http_error(self, e):
self.logger.error(f"Request failed: {str(e)}")
self.logger.error(f"Response status code: {e.code}")
self.logger.error(f"Response headers: {e.headers}")
content = e.read().decode("utf-8")
self.logger.error(f"Response content: {content}")
if e.code == 403:
error_msg = (
"Received a 403 Forbidden error. Your session key might be invalid. "
"Please try logging out and logging in again. If the issue persists, "
"you can try using the claude.ai-curl provider as a workaround:\n"
"claudesync api logout\n"
"claudesync api login claude.ai-curl"
)
self.logger.error(error_msg)
raise ProviderError(error_msg)
raise ProviderError(f"API request failed: {str(e)}")

0 comments on commit 7575f8c

Please sign in to comment.