Skip to content

Commit

Permalink
Improve error codes. Reference: jellydn#39
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 1, 2024
1 parent ea0919d commit 055179b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rplugin/python3/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ def ask(
url, headers=self._headers(), json=data, stream=True
)
if response.status_code != 200:
raise Exception(f"Error fetching response: {response}")
error_messages = {
401: "Unauthorized. Make sure you have access to Copilot Chat.",
500: "Internal server error. Please try again later.",
400: "The developer of this plugin has made a mistake. Please report this issue.",
419: "You have been rate limited. Please try again later.",
}
raise Exception(error_messages.get(response.status_code,
f"Unknown error: {response.status_code}"))
for line in response.iter_lines():
line = line.decode("utf-8").replace("data: ", "").strip()
if line.startswith("[DONE]"):
Expand Down

0 comments on commit 055179b

Please sign in to comment.