diff --git a/api.md b/api.md index d6933bfb..cc2d93c7 100644 --- a/api.md +++ b/api.md @@ -2,8 +2,10 @@ ```python from gitpod.types import ( + ArbitraryData, AutomationTrigger, EnvironmentClass, + ErrorCode, FieldValue, OrganizationRole, Principal, diff --git a/src/gitpod/_exceptions.py b/src/gitpod/_exceptions.py index 93778359..e78213ca 100644 --- a/src/gitpod/_exceptions.py +++ b/src/gitpod/_exceptions.py @@ -2,10 +2,16 @@ from __future__ import annotations +from typing import TYPE_CHECKING, Any, Optional, cast from typing_extensions import Literal import httpx +from ._utils import is_dict +from ._models import construct_type +from .types.shared.error_code import ErrorCode +from .types.shared.arbitrary_data import ArbitraryData + __all__ = [ "BadRequestError", "AuthenticationError", @@ -37,12 +43,35 @@ class APIError(GitpodError): 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 + code: Optional[ErrorCode] = None + """ + The status code, which should be an enum value of + [google.rpc.Code][google.rpc.Code]. + """ + detail: Optional[ArbitraryData] = None + """ + Contains an arbitrary serialized message along with a @type that describes the + type of the serialized message. + """ + if TYPE_CHECKING: + # Stub to indicate that arbitrary properties are accepted. + # To access properties that are not valid identifiers you can use `getattr`, e.g. + # `getattr(obj, '$type')` + def __getattr__(self, attr: str) -> object: ... + + 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.code = cast(Any, construct_type(type_=Optional[ErrorCode], value=body.get("code"))) + self.detail = cast(Any, construct_type(type_=Optional[ArbitraryData], value=body.get("detail"))) + else: + self.code = None + self.detail = None + class APIResponseValidationError(APIError): response: httpx.Response diff --git a/src/gitpod/types/__init__.py b/src/gitpod/types/__init__.py index 03e376b2..2b8a052a 100644 --- a/src/gitpod/types/__init__.py +++ b/src/gitpod/types/__init__.py @@ -13,10 +13,12 @@ RunsOn as RunsOn, Subject as Subject, TaskSpec as TaskSpec, + ErrorCode as ErrorCode, Principal as Principal, FieldValue as FieldValue, UserStatus as UserStatus, TaskMetadata as TaskMetadata, + ArbitraryData as ArbitraryData, TaskExecution as TaskExecution, EnvironmentClass as EnvironmentClass, OrganizationRole as OrganizationRole, diff --git a/src/gitpod/types/shared/__init__.py b/src/gitpod/types/shared/__init__.py index ba0e2567..b4616dc9 100644 --- a/src/gitpod/types/shared/__init__.py +++ b/src/gitpod/types/shared/__init__.py @@ -5,9 +5,11 @@ from .subject import Subject as Subject from .principal import Principal as Principal from .task_spec import TaskSpec as TaskSpec +from .error_code import ErrorCode as ErrorCode from .field_value import FieldValue as FieldValue from .user_status import UserStatus as UserStatus from .task_metadata import TaskMetadata as TaskMetadata +from .arbitrary_data import ArbitraryData as ArbitraryData from .task_execution import TaskExecution as TaskExecution from .environment_class import EnvironmentClass as EnvironmentClass from .organization_role import OrganizationRole as OrganizationRole diff --git a/src/gitpod/types/shared/arbitrary_data.py b/src/gitpod/types/shared/arbitrary_data.py new file mode 100644 index 00000000..de1ead23 --- /dev/null +++ b/src/gitpod/types/shared/arbitrary_data.py @@ -0,0 +1,21 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import TYPE_CHECKING, Dict, Optional + +from ..._models import BaseModel + +__all__ = ["ArbitraryData"] + + +class ArbitraryData(BaseModel): + debug: Optional[Dict[str, object]] = None + + type: Optional[str] = None + + value: Optional[object] = None + + if TYPE_CHECKING: + # Stub to indicate that arbitrary properties are accepted. + # To access properties that are not valid identifiers you can use `getattr`, e.g. + # `getattr(obj, '$type')` + def __getattr__(self, attr: str) -> object: ... diff --git a/src/gitpod/types/shared/error_code.py b/src/gitpod/types/shared/error_code.py new file mode 100644 index 00000000..316948ab --- /dev/null +++ b/src/gitpod/types/shared/error_code.py @@ -0,0 +1,24 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing_extensions import Literal, TypeAlias + +__all__ = ["ErrorCode"] + +ErrorCode: TypeAlias = Literal[ + "canceled", + "unknown", + "invalid_argument", + "deadline_exceeded", + "not_found", + "already_exists", + "permission_denied", + "resource_exhausted", + "failed_precondition", + "aborted", + "out_of_range", + "unimplemented", + "internal", + "unavailable", + "data_loss", + "unauthenticated", +]