diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-04-26 18:39:04 +0200 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-04-26 18:39:04 +0200 |
| commit | 6ae66e51f29c60537b7e931f85cc6f452b6cc651 (patch) | |
| tree | 9a8333923e4ed46a3e2cac7b049487feadfea657 | |
| parent | 7f0d980ce464edf0eb682d887107f0b14321ad94 (diff) | |
| download | vim-ai-6ae66e51f29c60537b7e931f85cc6f452b6cc651.tar.gz | |
http error handling
Diffstat (limited to '')
| -rw-r--r-- | py/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/py/utils.py b/py/utils.py index 22d4079..dc86f34 100644 --- a/py/utils.py +++ b/py/utils.py @@ -7,6 +7,7 @@ import urllib.request import socket import re from urllib.error import URLError +from urllib.error import HTTPError is_debugging = vim.eval("g:vim_ai_debug") == "1" debug_log_file = vim.eval("g:vim_ai_debug_log_file") @@ -145,5 +146,15 @@ def handle_completion_error(error): print_info_message("Completion cancelled...") elif isinstance(error, URLError) and isinstance(error.reason, socket.timeout): print_info_message("Request timeout...") + elif isinstance(error, HTTPError): + status_code = error.getcode() + msg = f"OpenAI: HTTPError {status_code}" + if status_code == 401: + msg += ' (Hint: verify that your API key is valid)' + if status_code == 404: + msg += ' (Hint: verify that you have access to the OpenAI API and to the model)' + elif status_code == 429: + msg += ' (Hint: verify that your billing plan is "Pay as you go")' + print_info_message(msg) else: raise error |