zach commited on
Commit
fe85e28
·
1 Parent(s): 633a175

Add custom error message for Hume APInrate limit error

Browse files
Files changed (2) hide show
  1. src/constants.py +1 -0
  2. src/integrations/hume_api.py +7 -3
src/constants.py CHANGED
@@ -12,6 +12,7 @@ from src.custom_types import ComparisonType, OptionKey, OptionLabel, TTSProvider
12
 
13
  CLIENT_ERROR_CODE = 400
14
  SERVER_ERROR_CODE = 500
 
15
 
16
 
17
  # UI constants
 
12
 
13
  CLIENT_ERROR_CODE = 400
14
  SERVER_ERROR_CODE = 500
15
+ RATE_LIMIT_ERROR_CODE = 429
16
 
17
 
18
  # UI constants
src/integrations/hume_api.py CHANGED
@@ -25,7 +25,7 @@ from tenacity import after_log, before_log, retry, retry_if_exception, stop_afte
25
 
26
  # Local Application Imports
27
  from src.config import Config, logger
28
- from src.constants import CLIENT_ERROR_CODE, GENERIC_API_ERROR_MESSAGE, SERVER_ERROR_CODE
29
  from src.utils import save_base64_audio_to_file, validate_env_var
30
 
31
 
@@ -143,8 +143,12 @@ async def text_to_speech_with_hume(
143
  clean_message = _extract_hume_api_error_message(e)
144
  logger.error(f"Full Hume API error: {e!s}")
145
 
146
- if e.status_code is not None and CLIENT_ERROR_CODE <= e.status_code < SERVER_ERROR_CODE:
147
- raise UnretryableHumeError(message=clean_message, original_exception=e) from e
 
 
 
 
148
 
149
  raise HumeError(message=clean_message, original_exception=e) from e
150
 
 
25
 
26
  # Local Application Imports
27
  from src.config import Config, logger
28
+ from src.constants import CLIENT_ERROR_CODE, GENERIC_API_ERROR_MESSAGE, RATE_LIMIT_ERROR_CODE, SERVER_ERROR_CODE
29
  from src.utils import save_base64_audio_to_file, validate_env_var
30
 
31
 
 
143
  clean_message = _extract_hume_api_error_message(e)
144
  logger.error(f"Full Hume API error: {e!s}")
145
 
146
+ if e.status_code is not None:
147
+ if e.status_code == RATE_LIMIT_ERROR_CODE:
148
+ rate_limit_error_message = "We're working on scaling capacity. Please try again in a few seconds."
149
+ raise HumeError(message=rate_limit_error_message, original_exception=e) from e
150
+ if CLIENT_ERROR_CODE <= e.status_code < SERVER_ERROR_CODE:
151
+ raise UnretryableHumeError(message=clean_message, original_exception=e) from e
152
 
153
  raise HumeError(message=clean_message, original_exception=e) from e
154