11from __future__ import annotations
22
3- from json import JSONDecodeError
43from typing import Any , Generic , Optional , TypeVar , Union
54
65from httpx import Headers , QueryParams
1918 pre_update ,
2019 pre_upsert ,
2120)
22- from ..exceptions import APIError , generate_default_error_message
21+ from ..exceptions import APIError , APIErrorFromJSON , generate_default_error_message
2322from ..types import ReturnMethod
2423from ..utils import SyncClient , get_origin_and_cast
2524
@@ -75,10 +74,9 @@ def execute(self) -> APIResponse[_ReturnT]:
7574 return body
7675 return APIResponse [_ReturnT ].from_http_request_response (r )
7776 else :
78- raise APIError (r .json ())
77+ json_obj = APIErrorFromJSON .model_validate_json (r .content )
78+ raise APIError (dict (json_obj ))
7979 except ValidationError as e :
80- raise APIError (r .json ()) from e
81- except JSONDecodeError :
8280 raise APIError (generate_default_error_message (r ))
8381
8482
@@ -124,10 +122,9 @@ def execute(self) -> SingleAPIResponse[_ReturnT]:
124122 ): # Response.ok from JS (https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
125123 return SingleAPIResponse [_ReturnT ].from_http_request_response (r )
126124 else :
127- raise APIError (r .json ())
125+ json_obj = APIErrorFromJSON .model_validate_json (r .content )
126+ raise APIError (dict (json_obj ))
128127 except ValidationError as e :
129- raise APIError (r .json ()) from e
130- except JSONDecodeError :
131128 raise APIError (generate_default_error_message (r ))
132129
133130
@@ -290,7 +287,7 @@ def select(
290287 *columns: The names of the columns to fetch.
291288 count: The method to use to get the count of rows returned.
292289 Returns:
293- :class:`SyncSelectRequestBuilder `
290+ :class:`AsyncSelectRequestBuilder `
294291 """
295292 method , params , headers , json = pre_select (* columns , count = count , head = head )
296293 return SyncSelectRequestBuilder [_ReturnT ](
@@ -317,7 +314,7 @@ def insert(
317314 Otherwise, use the default value for the column.
318315 Only applies for bulk inserts.
319316 Returns:
320- :class:`SyncQueryRequestBuilder `
317+ :class:`AsyncQueryRequestBuilder `
321318 """
322319 method , params , headers , json = pre_insert (
323320 json ,
@@ -353,7 +350,7 @@ def upsert(
353350 not when merging with existing rows under `ignoreDuplicates: false`.
354351 This also only applies when doing bulk upserts.
355352 Returns:
356- :class:`SyncQueryRequestBuilder `
353+ :class:`AsyncQueryRequestBuilder `
357354 """
358355 method , params , headers , json = pre_upsert (
359356 json ,
@@ -381,7 +378,7 @@ def update(
381378 count: The method to use to get the count of rows returned.
382379 returning: Either 'minimal' or 'representation'
383380 Returns:
384- :class:`SyncFilterRequestBuilder `
381+ :class:`AsyncFilterRequestBuilder `
385382 """
386383 method , params , headers , json = pre_update (
387384 json ,
@@ -404,7 +401,7 @@ def delete(
404401 count: The method to use to get the count of rows returned.
405402 returning: Either 'minimal' or 'representation'
406403 Returns:
407- :class:`SyncFilterRequestBuilder `
404+ :class:`AsyncFilterRequestBuilder `
408405 """
409406 method , params , headers , json = pre_delete (
410407 count = count ,
0 commit comments