From 70094ea765092cde765968e3ec24ce87ab6b6731 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Mon, 4 Dec 2023 16:43:31 -0500 Subject: [PATCH] handle openai.RateLimitError --- backend/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/main.py b/backend/main.py index 9056db4..bd38807 100644 --- a/backend/main.py +++ b/backend/main.py @@ -218,6 +218,17 @@ async def stream_code(websocket: WebSocket): ) ) return await throw_error(error_message) + except openai.RateLimitError as e: + print("[GENERATE_CODE] Rate limit exceeded", e) + error_message = ( + "OpenAI error - 'You exceeded your current quota, please check your plan and billing details.'" + + ( + " Alternatively, you can purchase code generation credits directly on this website." + if IS_PROD + else "" + ) + ) + return await throw_error(error_message) # Write the messages dict into a log so that we can debug later write_logs(prompt_messages, completion)