Skip to content

Commit ea6731a

Browse files
committed
Actually commit everything...
1 parent 9c1a9ee commit ea6731a

16 files changed

+602
-1090
lines changed

src/unstructured_client/basesdk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def do():
249249

250250
if http_res is None:
251251
logger.debug("Raising no response SDK error")
252-
raise errors.SDKError("No response received")
252+
raise errors.NoResponseError("No response received")
253253

254254
logger.debug(
255255
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
@@ -270,7 +270,7 @@ def do():
270270
http_res = result
271271
else:
272272
logger.debug("Raising unexpected SDK error")
273-
raise errors.SDKError("Unexpected error occurred")
273+
raise errors.SDKError("Unexpected error occurred", http_res)
274274

275275
return http_res
276276

@@ -321,7 +321,7 @@ async def do():
321321

322322
if http_res is None:
323323
logger.debug("Raising no response SDK error")
324-
raise errors.SDKError("No response received")
324+
raise errors.NoResponseError("No response received")
325325

326326
logger.debug(
327327
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
@@ -342,7 +342,7 @@ async def do():
342342
http_res = result
343343
else:
344344
logger.debug("Raising unexpected SDK error")
345-
raise errors.SDKError("Unexpected error occurred")
345+
raise errors.SDKError("Unexpected error occurred", http_res)
346346

347347
return http_res
348348

src/unstructured_client/destinations.py

Lines changed: 111 additions & 266 deletions
Large diffs are not rendered by default.

src/unstructured_client/general.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unstructured_client._hooks import HookContext
88
from unstructured_client.models import errors, operations, shared
99
from unstructured_client.types import BaseModel, OptionalNullable, UNSET
10+
from unstructured_client._hooks.custom.clean_server_url_hook import clean_server_url
1011
from unstructured_client.utils.unmarshal_json_response import unmarshal_json_response
1112

1213

src/unstructured_client/jobs.py

Lines changed: 93 additions & 224 deletions
Large diffs are not rendered by default.

src/unstructured_client/models/errors/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,34 @@
99
HTTPValidationError,
1010
HTTPValidationErrorData,
1111
)
12+
from .no_response_error import NoResponseError
13+
from .responsevalidationerror import ResponseValidationError
1214
from .sdkerror import SDKError
1315
from .servererror import ServerError, ServerErrorData
16+
from .unstructuredclienterror import UnstructuredClientError
1417

1518
__all__ = [
1619
"Detail",
1720
"HTTPValidationError",
1821
"HTTPValidationErrorData",
22+
"NoResponseError",
23+
"ResponseValidationError",
1924
"SDKError",
2025
"ServerError",
2126
"ServerErrorData",
27+
"UnstructuredClientError",
2228
]
2329

2430
_dynamic_imports: dict[str, str] = {
2531
"Detail": ".httpvalidationerror",
2632
"HTTPValidationError": ".httpvalidationerror",
2733
"HTTPValidationErrorData": ".httpvalidationerror",
34+
"NoResponseError": ".no_response_error",
35+
"ResponseValidationError": ".responsevalidationerror",
2836
"SDKError": ".sdkerror",
2937
"ServerError": ".servererror",
3038
"ServerErrorData": ".servererror",
39+
"UnstructuredClientError": ".unstructuredclienterror",
3140
}
3241

3342

src/unstructured_client/models/errors/httpvalidationerror.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
22

33
from __future__ import annotations
4+
import httpx
45
from typing import List, Optional, Union
56
from typing_extensions import TypeAliasType
6-
from unstructured_client import utils
7+
from unstructured_client.models.errors import UnstructuredClientError
78
from unstructured_client.models.shared import validationerror as shared_validationerror
89
from unstructured_client.types import BaseModel
910

@@ -22,11 +23,15 @@ class HTTPValidationErrorData(BaseModel):
2223
detail: Optional[Detail] = None
2324

2425

25-
class HTTPValidationError(Exception):
26+
class HTTPValidationError(UnstructuredClientError):
2627
data: HTTPValidationErrorData
2728

28-
def __init__(self, data: HTTPValidationErrorData):
29+
def __init__(
30+
self,
31+
data: HTTPValidationErrorData,
32+
raw_response: httpx.Response,
33+
body: Optional[str] = None,
34+
):
35+
message = body or raw_response.text
36+
super().__init__(message, raw_response, body)
2937
self.data = data
30-
31-
def __str__(self) -> str:
32-
return utils.marshal_json(self.data, HTTPValidationErrorData)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2+
3+
class NoResponseError(Exception):
4+
"""Error raised when no HTTP response is received from the server."""
5+
6+
message: str
7+
8+
def __init__(self, message: str = "No response received"):
9+
self.message = message
10+
super().__init__(message)
11+
12+
def __str__(self):
13+
return self.message
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2+
3+
import httpx
4+
from typing import Optional
5+
6+
from unstructured_client.models.errors import UnstructuredClientError
7+
8+
9+
class ResponseValidationError(UnstructuredClientError):
10+
"""Error raised when there is a type mismatch between the response data and the expected Pydantic model."""
11+
12+
def __init__(
13+
self,
14+
message: str,
15+
raw_response: httpx.Response,
16+
cause: Exception,
17+
body: Optional[str] = None,
18+
):
19+
message = f"{message}: {cause}"
20+
super().__init__(message, raw_response, body)
21+
22+
@property
23+
def cause(self):
24+
"""Normally the Pydantic ValidationError"""
25+
return self.__cause__
Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
22

3-
from dataclasses import dataclass
4-
from typing import Optional
53
import httpx
4+
from typing import Optional
5+
6+
from unstructured_client.models.errors import UnstructuredClientError
7+
8+
MAX_MESSAGE_LEN = 10_000
9+
10+
11+
class SDKError(UnstructuredClientError):
12+
"""The fallback error class if no more specific error class is matched."""
13+
14+
def __init__(
15+
self, message: str, raw_response: httpx.Response, body: Optional[str] = None
16+
):
17+
body_display = body or raw_response.text or '""'
618

19+
if message:
20+
message += ": "
21+
message += f"Status {raw_response.status_code}"
722

8-
@dataclass
9-
class SDKError(Exception):
10-
"""Represents an error returned by the API."""
23+
headers = raw_response.headers
24+
content_type = headers.get("content-type", '""')
25+
if content_type != "application/json":
26+
if " " in content_type:
27+
content_type = f'"{content_type}"'
28+
message += f" Content-Type {content_type}"
1129

12-
message: str
13-
status_code: int = -1
14-
body: str = ""
15-
raw_response: Optional[httpx.Response] = None
30+
if len(body_display) > MAX_MESSAGE_LEN:
31+
truncated = body_display[:MAX_MESSAGE_LEN]
32+
remaining = len(body_display) - MAX_MESSAGE_LEN
33+
body_display = f"{truncated}...and {remaining} more chars"
1634

17-
def __str__(self):
18-
body = ""
19-
if len(self.body) > 0:
20-
body = f"\n{self.body}"
35+
message += f". Body: {body_display}"
36+
message = message.strip()
2137

22-
return f"{self.message}: Status {self.status_code}{body}"
38+
super().__init__(message, raw_response, body)

src/unstructured_client/models/errors/servererror.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
22

33
from __future__ import annotations
4+
import httpx
45
from typing import Optional
5-
from unstructured_client import utils
6+
from unstructured_client.models.errors import UnstructuredClientError
67
from unstructured_client.types import BaseModel
78

89

910
class ServerErrorData(BaseModel):
1011
detail: Optional[str] = None
1112

1213

13-
class ServerError(Exception):
14+
class ServerError(UnstructuredClientError):
1415
data: ServerErrorData
1516

16-
def __init__(self, data: ServerErrorData):
17+
def __init__(
18+
self,
19+
data: ServerErrorData,
20+
raw_response: httpx.Response,
21+
body: Optional[str] = None,
22+
):
23+
message = body or raw_response.text
24+
super().__init__(message, raw_response, body)
1725
self.data = data
18-
19-
def __str__(self) -> str:
20-
return utils.marshal_json(self.data, ServerErrorData)

0 commit comments

Comments
 (0)