From cc6478b7beedfe9bbb96c35d81f4b0a1339cd73f Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Thu, 21 Mar 2024 11:15:49 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- api.md | 6 ++++++ src/cloudflare/_exceptions.py | 14 +++++++++++++- src/cloudflare/types/__init__.py | 1 + src/cloudflare/types/shared/__init__.py | 3 +++ src/cloudflare/types/shared/error_data.py | 13 +++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/cloudflare/types/shared/__init__.py create mode 100644 src/cloudflare/types/shared/error_data.py diff --git a/api.md b/api.md index aaf8d4f374b..eb000051e6a 100644 --- a/api.md +++ b/api.md @@ -1,3 +1,9 @@ +# Shared Types + +```python +from cloudflare.types import ErrorData +``` + # Accounts Types: diff --git a/src/cloudflare/_exceptions.py b/src/cloudflare/_exceptions.py index 9c9407f652e..5c2b9e5a263 100644 --- a/src/cloudflare/_exceptions.py +++ b/src/cloudflare/_exceptions.py @@ -2,10 +2,15 @@ from __future__ import annotations +from typing import Any, List, cast from typing_extensions import Literal import httpx +from ._utils import is_dict +from ._models import construct_type +from .types.shared import ErrorData + __all__ = [ "BadRequestError", "AuthenticationError", @@ -37,12 +42,19 @@ class APIError(CloudflareError): If there was no response associated with this error then it will be `None`. """ - def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None: # noqa: ARG002 + errors: List[ErrorData] + + def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None: super().__init__(message) self.request = request self.message = message self.body = body + if is_dict(body): + self.errors = cast(Any, construct_type(type_=List[ErrorData], value=body.get("errors"))) + else: + self.errors = [] + class APIResponseValidationError(APIError): response: httpx.Response diff --git a/src/cloudflare/types/__init__.py b/src/cloudflare/types/__init__.py index 54326eb97a7..f9c90ca3150 100644 --- a/src/cloudflare/types/__init__.py +++ b/src/cloudflare/types/__init__.py @@ -4,6 +4,7 @@ from .ips import IPs as IPs from .zone import Zone as Zone +from .shared import ErrorData as ErrorData from .account import Account as Account from .snippet import Snippet as Snippet from .calls_app import CallsApp as CallsApp diff --git a/src/cloudflare/types/shared/__init__.py b/src/cloudflare/types/shared/__init__.py new file mode 100644 index 00000000000..28c422b2fc6 --- /dev/null +++ b/src/cloudflare/types/shared/__init__.py @@ -0,0 +1,3 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .error_data import ErrorData as ErrorData diff --git a/src/cloudflare/types/shared/error_data.py b/src/cloudflare/types/shared/error_data.py new file mode 100644 index 00000000000..e7621bcad3f --- /dev/null +++ b/src/cloudflare/types/shared/error_data.py @@ -0,0 +1,13 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from ..._models import BaseModel + +__all__ = ["ErrorData"] + + +class ErrorData(BaseModel): + code: Optional[int] = None + + message: Optional[str] = None