refactor: Update AnthropicModelComponent to handle ImportError gracefully

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-20 18:18:09 -03:00
commit 6b3a8b69bc

View file

@ -98,9 +98,9 @@ class AnthropicModelComponent(LCModelComponent):
try:
from anthropic import BadRequestError
except ImportError:
return
return None
if isinstance(exception, BadRequestError):
message = exception.body.get("error", {}).get("message") # type: ignore
if message:
return message
return
return None