Commit 046daf6e

Stainless Bot <107565488+stainless-bot@users.noreply.github.com>
2024-03-21 18:36:29
chore(internal): construct error properties instead of using the raw response (#1257)
1 parent 73869ee
Changed files (1)
src
src/openai/_exceptions.py
@@ -8,6 +8,7 @@ from typing_extensions import Literal
 import httpx
 
 from ._utils import is_dict
+from ._models import construct_type
 
 __all__ = [
     "BadRequestError",
@@ -51,9 +52,9 @@ class APIError(OpenAIError):
         self.body = body
 
         if is_dict(body):
-            self.code = cast(Any, body.get("code"))
-            self.param = cast(Any, body.get("param"))
-            self.type = cast(Any, body.get("type"))
+            self.code = cast(Any, construct_type(type_=Optional[str], value=body.get("code")))
+            self.param = cast(Any, construct_type(type_=Optional[str], value=body.get("param")))
+            self.type = cast(Any, construct_type(type_=str, value=body.get("type")))
         else:
             self.code = None
             self.param = None