Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conjure_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ConjureUnionType",
"DecodableType",
"DictType",
"ErrorCode",
"ListType",
"OptionalType",
"OptionalTypeWrapper",
Expand Down
2 changes: 2 additions & 0 deletions conjure_python_client/_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from .configuration import SslConfiguration, ServiceConfiguration
from .errors import ErrorCode
from .requests_client import RequestsClient, Service, ConjureHTTPError

__all__ = [
Expand All @@ -21,4 +22,5 @@
"RequestsClient",
"Service",
"ConjureHTTPError",
"ErrorCode",
]
34 changes: 34 additions & 0 deletions conjure_python_client/_http/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from enum import Enum


class ErrorCode(str, Enum):
"""Conjure error codes as defined in the Conjure specification."""

PERMISSION_DENIED = "PERMISSION_DENIED"
INVALID_ARGUMENT = "INVALID_ARGUMENT"
NOT_FOUND = "NOT_FOUND"
CONFLICT = "CONFLICT"
REQUEST_ENTITY_TOO_LARGE = "REQUEST_ENTITY_TOO_LARGE"
FAILED_PRECONDITION = "FAILED_PRECONDITION"
INTERNAL = "INTERNAL"
TIMEOUT = "TIMEOUT"
CUSTOM_CLIENT = "CUSTOM_CLIENT"
CUSTOM_SERVER = "CUSTOM_SERVER"

def __str__(self) -> str:
"""Return just the string value"""
return self.value
3 changes: 2 additions & 1 deletion conjure_python_client/_http/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
from requests.packages.urllib3.util import Retry
from .configuration import ServiceConfiguration
from .errors import ErrorCode

import binascii
import os
Expand Down Expand Up @@ -260,7 +261,7 @@ class ConjureHTTPError(HTTPError):
attributes extracted from the response."""

_cause: Optional[HTTPError]
_error_code: str
_error_code: ErrorCode
_error_name: str
_error_instance_id: str
_parameters: Dict[str, str]
Expand Down
30 changes: 30 additions & 0 deletions test/_http/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from conjure_python_client import ErrorCode


class TestErrorCode:
def test_string_convertion(self):
assert str(ErrorCode.NOT_FOUND) == "NOT_FOUND"
assert str(ErrorCode.INVALID_ARGUMENT) == "INVALID_ARGUMENT"

def test_error_code_string_equality(self):
assert ErrorCode.NOT_FOUND == "NOT_FOUND"
assert ErrorCode.INVALID_ARGUMENT == "INVALID_ARGUMENT"
assert ErrorCode.NOT_FOUND != "INVALID_ARGUMENT"

def test_error_code_creation_from_string(self):
assert ErrorCode("NOT_FOUND") == ErrorCode.NOT_FOUND
assert ErrorCode("INVALID_ARGUMENT") == ErrorCode.INVALID_ARGUMENT