refactor: Update get_message_from_openai_exception to handle None return value

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-19 20:01:14 -03:00
commit b8b14bb36a

View file

@ -1,4 +1,4 @@
def get_message_from_openai_exception(exception: Exception) -> str:
def get_message_from_openai_exception(exception: Exception) -> str | None:
"""
Get a message from an OpenAI exception.
@ -13,7 +13,7 @@ def get_message_from_openai_exception(exception: Exception) -> str:
except ImportError:
return
if isinstance(exception, BadRequestError):
message = exception.body.get("message")
message = exception.body.get("message") # type: ignore
if message:
return message
return