Spaces:
Running
Running
zach
commited on
Commit
·
2192d9b
1
Parent(s):
8fc5d19
Update generic error message
Browse files- src/constants.py +2 -0
- src/integrations/elevenlabs_api.py +3 -3
- src/integrations/hume_api.py +4 -4
src/constants.py
CHANGED
@@ -38,6 +38,8 @@ TROPHY_EMOJI: str = "🏆"
|
|
38 |
SELECT_OPTION_A: str = "Select Option A"
|
39 |
SELECT_OPTION_B: str = "Select Option B"
|
40 |
|
|
|
|
|
41 |
# A collection of pre-defined character descriptions categorized by theme, used to provide users with
|
42 |
# inspiration for generating creative, expressive text inputs for TTS, and generating novel voices.
|
43 |
SAMPLE_CHARACTER_DESCRIPTIONS: dict = {
|
|
|
38 |
SELECT_OPTION_A: str = "Select Option A"
|
39 |
SELECT_OPTION_B: str = "Select Option B"
|
40 |
|
41 |
+
GENERIC_API_ERROR_MESSAGE: str = "An unexpected error occurred while processing your request. Please try again shortly."
|
42 |
+
|
43 |
# A collection of pre-defined character descriptions categorized by theme, used to provide users with
|
44 |
# inspiration for generating creative, expressive text inputs for TTS, and generating novel voices.
|
45 |
SAMPLE_CHARACTER_DESCRIPTIONS: dict = {
|
src/integrations/elevenlabs_api.py
CHANGED
@@ -26,7 +26,7 @@ from tenacity import after_log, before_log, retry, retry_if_exception, stop_afte
|
|
26 |
|
27 |
# Local Application Imports
|
28 |
from src.config import Config, logger
|
29 |
-
from src.constants import CLIENT_ERROR_CODE, SERVER_ERROR_CODE
|
30 |
from src.utils import save_base64_audio_to_file, validate_env_var
|
31 |
|
32 |
|
@@ -140,7 +140,7 @@ async def text_to_speech_with_elevenlabs(
|
|
140 |
error_type = type(e).__name__
|
141 |
error_message = str(e) if str(e) else f"An error of type {error_type} occurred"
|
142 |
logger.error(f"Error during ElevenLabs API call: {error_type} - {error_message}")
|
143 |
-
clean_message =
|
144 |
|
145 |
raise ElevenLabsError(message=error_message, original_exception=e) from e
|
146 |
|
@@ -155,7 +155,7 @@ def _extract_elevenlabs_error_message(e: ApiError) -> str:
|
|
155 |
Returns:
|
156 |
str: A clean, user-friendly error message suitable for display to end users.
|
157 |
"""
|
158 |
-
clean_message =
|
159 |
|
160 |
if (
|
161 |
hasattr(e, 'body') and e.body
|
|
|
26 |
|
27 |
# Local Application Imports
|
28 |
from src.config import Config, logger
|
29 |
+
from src.constants import CLIENT_ERROR_CODE, GENERIC_API_ERROR_MESSAGE, SERVER_ERROR_CODE
|
30 |
from src.utils import save_base64_audio_to_file, validate_env_var
|
31 |
|
32 |
|
|
|
140 |
error_type = type(e).__name__
|
141 |
error_message = str(e) if str(e) else f"An error of type {error_type} occurred"
|
142 |
logger.error(f"Error during ElevenLabs API call: {error_type} - {error_message}")
|
143 |
+
clean_message = GENERIC_API_ERROR_MESSAGE
|
144 |
|
145 |
raise ElevenLabsError(message=error_message, original_exception=e) from e
|
146 |
|
|
|
155 |
Returns:
|
156 |
str: A clean, user-friendly error message suitable for display to end users.
|
157 |
"""
|
158 |
+
clean_message = GENERIC_API_ERROR_MESSAGE
|
159 |
|
160 |
if (
|
161 |
hasattr(e, 'body') and e.body
|
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, SERVER_ERROR_CODE
|
29 |
from src.utils import save_base64_audio_to_file, validate_env_var
|
30 |
|
31 |
|
@@ -152,7 +152,7 @@ async def text_to_speech_with_hume(
|
|
152 |
error_type = type(e).__name__
|
153 |
error_message = str(e) if str(e) else f"An error of type {error_type} occurred"
|
154 |
logger.error("Error during Hume API call: %s - %s", error_type, error_message)
|
155 |
-
clean_message =
|
156 |
|
157 |
raise HumeError(message=clean_message, original_exception=e) from e
|
158 |
|
@@ -167,9 +167,9 @@ def _extract_hume_api_error_message(e: ApiError) -> str:
|
|
167 |
Returns:
|
168 |
str: A clean, user-friendly error message suitable for display to end users.
|
169 |
"""
|
170 |
-
clean_message =
|
171 |
|
172 |
if hasattr(e, 'body') and isinstance(e.body, dict) and 'message' in e.body:
|
173 |
-
|
174 |
|
175 |
return clean_message
|
|
|
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 |
|
|
|
152 |
error_type = type(e).__name__
|
153 |
error_message = str(e) if str(e) else f"An error of type {error_type} occurred"
|
154 |
logger.error("Error during Hume API call: %s - %s", error_type, error_message)
|
155 |
+
clean_message = GENERIC_API_ERROR_MESSAGE
|
156 |
|
157 |
raise HumeError(message=clean_message, original_exception=e) from e
|
158 |
|
|
|
167 |
Returns:
|
168 |
str: A clean, user-friendly error message suitable for display to end users.
|
169 |
"""
|
170 |
+
clean_message = GENERIC_API_ERROR_MESSAGE
|
171 |
|
172 |
if hasattr(e, 'body') and isinstance(e.body, dict) and 'message' in e.body:
|
173 |
+
clean_message = e.body['message']
|
174 |
|
175 |
return clean_message
|