Skip to content

Commit

Permalink
fix: Work with non-json error messages #90
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 28, 2024
1 parent 6a222a6 commit 5208678
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rplugin/python3/CopilotChat/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ def ask(
f.write(f"Error: {response.status_code}\n")
f.write(f"Request: {data}\n")
f.write(f"Response: {response.text}\n")

error_code = response.json().get("error", {}).get("code")
try:
error_code = response.json().get("error", {}).get("code")
except json.decoder.JSONDecodeError:
error_code = 0
error_messages[error_code] = response.text
if error_code and error_messages.get(response.status_code):
error_messages[response.status_code] = (
f"{error_messages[response.status_code]}: {error_code}"
Expand Down

0 comments on commit 5208678

Please sign in to comment.