44import warnings
55from hyperbrowser .exceptions import HyperbrowserError
66from ...file_utils import ensure_existing_file_path
7+ from ..serialization_utils import serialize_model_dump_to_dict
78from ..session_utils import (
89 parse_session_recordings_response_data ,
910 parse_session_response_model ,
@@ -36,17 +37,10 @@ async def list(
3637 params : Optional [SessionEventLogListParams ] = None ,
3738 ) -> SessionEventLogListResponse :
3839 params_obj = params or SessionEventLogListParams ()
39- try :
40- query_params = params_obj .model_dump (exclude_none = True , by_alias = True )
41- except HyperbrowserError :
42- raise
43- except Exception as exc :
44- raise HyperbrowserError (
45- "Failed to serialize session event log params" ,
46- original_error = exc ,
47- ) from exc
48- if type (query_params ) is not dict :
49- raise HyperbrowserError ("Failed to serialize session event log params" )
40+ query_params = serialize_model_dump_to_dict (
41+ params_obj ,
42+ error_message = "Failed to serialize session event log params" ,
43+ )
5044 response = await self ._client .transport .get (
5145 self ._client ._build_url (f"/session/{ session_id } /event-logs" ),
5246 params = query_params ,
@@ -70,17 +64,10 @@ async def create(
7064 ) -> SessionDetail :
7165 payload = {}
7266 if params is not None :
73- try :
74- payload = params .model_dump (exclude_none = True , by_alias = True )
75- except HyperbrowserError :
76- raise
77- except Exception as exc :
78- raise HyperbrowserError (
79- "Failed to serialize session create params" ,
80- original_error = exc ,
81- ) from exc
82- if type (payload ) is not dict :
83- raise HyperbrowserError ("Failed to serialize session create params" )
67+ payload = serialize_model_dump_to_dict (
68+ params ,
69+ error_message = "Failed to serialize session create params" ,
70+ )
8471 response = await self ._client .transport .post (
8572 self ._client ._build_url ("/session" ),
8673 data = payload ,
@@ -95,17 +82,10 @@ async def get(
9582 self , id : str , params : Optional [SessionGetParams ] = None
9683 ) -> SessionDetail :
9784 params_obj = params or SessionGetParams ()
98- try :
99- query_params = params_obj .model_dump (exclude_none = True , by_alias = True )
100- except HyperbrowserError :
101- raise
102- except Exception as exc :
103- raise HyperbrowserError (
104- "Failed to serialize session get params" ,
105- original_error = exc ,
106- ) from exc
107- if type (query_params ) is not dict :
108- raise HyperbrowserError ("Failed to serialize session get params" )
85+ query_params = serialize_model_dump_to_dict (
86+ params_obj ,
87+ error_message = "Failed to serialize session get params" ,
88+ )
10989 response = await self ._client .transport .get (
11090 self ._client ._build_url (f"/session/{ id } " ),
11191 params = query_params ,
@@ -130,17 +110,10 @@ async def list(
130110 self , params : Optional [SessionListParams ] = None
131111 ) -> SessionListResponse :
132112 params_obj = params or SessionListParams ()
133- try :
134- query_params = params_obj .model_dump (exclude_none = True , by_alias = True )
135- except HyperbrowserError :
136- raise
137- except Exception as exc :
138- raise HyperbrowserError (
139- "Failed to serialize session list params" ,
140- original_error = exc ,
141- ) from exc
142- if type (query_params ) is not dict :
143- raise HyperbrowserError ("Failed to serialize session list params" )
113+ query_params = serialize_model_dump_to_dict (
114+ params_obj ,
115+ error_message = "Failed to serialize session list params" ,
116+ )
144117 response = await self ._client .transport .get (
145118 self ._client ._build_url ("/sessions" ),
146119 params = query_params ,
@@ -318,17 +291,10 @@ async def update_profile_params(
318291 "update_profile_params() requires either UpdateSessionProfileParams or a boolean persist_changes."
319292 )
320293
321- try :
322- serialized_params = params_obj .model_dump (exclude_none = True , by_alias = True )
323- except HyperbrowserError :
324- raise
325- except Exception as exc :
326- raise HyperbrowserError (
327- "Failed to serialize update_profile_params payload" ,
328- original_error = exc ,
329- ) from exc
330- if type (serialized_params ) is not dict :
331- raise HyperbrowserError ("Failed to serialize update_profile_params payload" )
294+ serialized_params = serialize_model_dump_to_dict (
295+ params_obj ,
296+ error_message = "Failed to serialize update_profile_params payload" ,
297+ )
332298
333299 response = await self ._client .transport .put (
334300 self ._client ._build_url (f"/session/{ id } /update" ),
0 commit comments