Skip to content

Commit

Permalink
Fix #181 - use request handler for db ops
Browse files Browse the repository at this point in the history
  • Loading branch information
erichare committed Jan 31, 2024
1 parent fa12397 commit 891e02d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions astrapy/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
from astrapy.utils import (
convert_vector_to_floats,
make_payload,
make_request,
http_methods,
amake_request,
normalize_for_api,
restore_from_api,
)
Expand Down Expand Up @@ -1879,24 +1877,25 @@ def _request(
json_data: Optional[Dict[str, Any]] = None,
url_params: Optional[Dict[str, Any]] = None,
skip_error_check: bool = False,
**kwargs: Any,
) -> API_RESPONSE:
response = make_request(
request_handler = APIRequestHandler(
client=self.client,
base_url=self.base_url,
auth_header=DEFAULT_AUTH_HEADER,
token=self.token,
method=method,
path=path,
json_data=json_data,
json_data=normalize_for_api(json_data),
url_params=url_params,
skip_error_check=skip_error_check,
**kwargs,
)

responsebody = cast(API_RESPONSE, response.json())
direct_response = request_handler.request()
response = restore_from_api(direct_response)

if not skip_error_check and "errors" in responsebody:
raise ValueError(json.dumps(responsebody["errors"]))
else:
return responsebody
return response

def collection(self, collection_name: str) -> AstraDBCollection:
"""
Expand Down Expand Up @@ -2115,24 +2114,25 @@ async def _request(
json_data: Optional[Dict[str, Any]] = None,
url_params: Optional[Dict[str, Any]] = None,
skip_error_check: bool = False,
**kwargs: Any,
) -> API_RESPONSE:
response = await amake_request(
request_handler = AsyncAPIRequestHandler(
client=self.client,
base_url=self.base_url,
auth_header=DEFAULT_AUTH_HEADER,
token=self.token,
method=method,
path=path,
json_data=json_data,
json_data=normalize_for_api(json_data),
url_params=url_params,
skip_error_check=skip_error_check,
**kwargs,
)

responsebody = cast(API_RESPONSE, response.json())
direct_response = await request_handler.request()
response = restore_from_api(direct_response)

if not skip_error_check and "errors" in responsebody:
raise ValueError(json.dumps(responsebody["errors"]))
else:
return responsebody
return response

async def collection(self, collection_name: str) -> AsyncAstraDBCollection:
"""
Expand Down

0 comments on commit 891e02d

Please sign in to comment.