77from unstructured_client ._hooks import HookContext
88from unstructured_client .models import errors , operations , shared
99from unstructured_client .types import BaseModel , OptionalNullable , UNSET
10- from unstructured_client ._hooks . custom . clean_server_url_hook import clean_server_url
10+ from unstructured_client .utils . unmarshal_json_response import unmarshal_json_response
1111
1212
1313class PartitionAcceptEnum (str , Enum ):
@@ -113,8 +113,8 @@ def partition(
113113 response_data : Any = None
114114 if utils .match_response (http_res , "200" , "application/json" ):
115115 return operations .PartitionResponse (
116- elements = utils . unmarshal_json (
117- http_res . text , Optional [List [Dict [str , Any ]]]
116+ elements = unmarshal_json_response (
117+ Optional [List [Dict [str , Any ]]], http_res
118118 ),
119119 status_code = http_res .status_code ,
120120 content_type = http_res .headers .get ("Content-Type" ) or "" ,
@@ -128,27 +128,18 @@ def partition(
128128 raw_response = http_res ,
129129 )
130130 if utils .match_response (http_res , "422" , "application/json" ):
131- response_data = utils . unmarshal_json (
132- http_res . text , errors .HTTPValidationErrorData
131+ response_data = unmarshal_json_response (
132+ errors .HTTPValidationErrorData , http_res
133133 )
134- raise errors .HTTPValidationError (data = response_data )
134+ raise errors .HTTPValidationError (response_data , http_res )
135135 if utils .match_response (http_res , "4XX" , "*" ):
136136 http_res_text = utils .stream_to_text (http_res )
137- raise errors .SDKError (
138- "API error occurred" , http_res .status_code , http_res_text , http_res
139- )
137+ raise errors .SDKError ("API error occurred" , http_res , http_res_text )
140138 if utils .match_response (http_res , "5XX" , "application/json" ):
141- response_data = utils . unmarshal_json ( http_res . text , errors .ServerErrorData )
142- raise errors .ServerError (data = response_data )
139+ response_data = unmarshal_json_response ( errors .ServerErrorData , http_res )
140+ raise errors .ServerError (response_data , http_res )
143141
144- content_type = http_res .headers .get ("Content-Type" )
145- http_res_text = utils .stream_to_text (http_res )
146- raise errors .SDKError (
147- f"Unexpected response received (code: { http_res .status_code } , type: { content_type } )" ,
148- http_res .status_code ,
149- http_res_text ,
150- http_res ,
151- )
142+ raise errors .SDKError ("Unexpected response received" , http_res )
152143
153144 async def partition_async (
154145 self ,
@@ -247,8 +238,8 @@ async def partition_async(
247238 response_data : Any = None
248239 if utils .match_response (http_res , "200" , "application/json" ):
249240 return operations .PartitionResponse (
250- elements = utils . unmarshal_json (
251- http_res . text , Optional [List [Dict [str , Any ]]]
241+ elements = unmarshal_json_response (
242+ Optional [List [Dict [str , Any ]]], http_res
252243 ),
253244 status_code = http_res .status_code ,
254245 content_type = http_res .headers .get ("Content-Type" ) or "" ,
@@ -262,24 +253,15 @@ async def partition_async(
262253 raw_response = http_res ,
263254 )
264255 if utils .match_response (http_res , "422" , "application/json" ):
265- response_data = utils . unmarshal_json (
266- http_res . text , errors .HTTPValidationErrorData
256+ response_data = unmarshal_json_response (
257+ errors .HTTPValidationErrorData , http_res
267258 )
268- raise errors .HTTPValidationError (data = response_data )
259+ raise errors .HTTPValidationError (response_data , http_res )
269260 if utils .match_response (http_res , "4XX" , "*" ):
270261 http_res_text = await utils .stream_to_text_async (http_res )
271- raise errors .SDKError (
272- "API error occurred" , http_res .status_code , http_res_text , http_res
273- )
262+ raise errors .SDKError ("API error occurred" , http_res , http_res_text )
274263 if utils .match_response (http_res , "5XX" , "application/json" ):
275- response_data = utils . unmarshal_json ( http_res . text , errors .ServerErrorData )
276- raise errors .ServerError (data = response_data )
264+ response_data = unmarshal_json_response ( errors .ServerErrorData , http_res )
265+ raise errors .ServerError (response_data , http_res )
277266
278- content_type = http_res .headers .get ("Content-Type" )
279- http_res_text = await utils .stream_to_text_async (http_res )
280- raise errors .SDKError (
281- f"Unexpected response received (code: { http_res .status_code } , type: { content_type } )" ,
282- http_res .status_code ,
283- http_res_text ,
284- http_res ,
285- )
267+ raise errors .SDKError ("Unexpected response received" , http_res )
0 commit comments