Improved exception messages (#479)

This commit is contained in:
Dmytro Struk
2025-08-25 07:46:48 -07:00
committed by GitHub
Unverified
parent e72cfa1d71
commit 4b9eea906f
4 changed files with 103 additions and 53 deletions
@@ -68,17 +68,17 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
except BadRequestError as ex:
if ex.code == "content_filter":
raise OpenAIContentFilterException(
f"{type(self)} service encountered a content error",
ex,
f"{type(self)} service encountered a content error: {ex}",
inner_exception=ex,
) from ex
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
ex,
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
except Exception as ex:
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
ex,
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
async def _inner_get_streaming_response(
@@ -98,17 +98,17 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
except BadRequestError as ex:
if ex.code == "content_filter":
raise OpenAIContentFilterException(
f"{type(self)} service encountered a content error",
ex,
f"{type(self)} service encountered a content error: {ex}",
inner_exception=ex,
) from ex
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
ex,
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
except Exception as ex:
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
ex,
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
# region content creation
@@ -312,16 +312,16 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
except BadRequestError as ex:
if ex.code == "content_filter":
raise OpenAIContentFilterException(
f"{type(self)} service encountered a content error",
f"{type(self)} service encountered a content error: {ex}",
inner_exception=ex,
) from ex
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
except Exception as ex:
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt, with exception: {ex}",
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
@@ -359,16 +359,16 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
except BadRequestError as ex:
if ex.code == "content_filter":
raise OpenAIContentFilterException(
f"{type(self)} service encountered a content error",
f"{type(self)} service encountered a content error: {ex}",
inner_exception=ex,
) from ex
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex
except Exception as ex:
raise ServiceResponseException(
f"{type(self)} service failed to complete the prompt",
f"{type(self)} service failed to complete the prompt: {ex}",
inner_exception=ex,
) from ex