Skip to content

Commit

Permalink
Validate attachment response and throw error (#396)
Browse files Browse the repository at this point in the history
* Validate attachment response and throw error

* Update nylas/handler/http_client.py

Co-authored-by: Aaron de Mello <[email protected]>

* Resolve PR comments

* Fix pylint warnings

* Check the status code before and remove utlity function

* Added changelog

---------

Co-authored-by: Aaron de Mello <[email protected]>
  • Loading branch information
kraju3 and AaronDDM authored Dec 16, 2024
1 parent b68c893 commit 5922f8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ nylas-python Changelog
Unreleased
--------------
* Add support for Scheduler APIs
* Fixed attachment download response handling

v6.4.0
----------------
Expand Down
6 changes: 4 additions & 2 deletions nylas/handler/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _validate_response(response: Response) -> dict:

return json


def _build_query_params(base_url: str, query_params: dict = None) -> str:
query_param_parts = []
for key, value in query_params.items():
Expand Down Expand Up @@ -109,7 +108,7 @@ def _execute_download_request(
query_params=None,
stream=False,
overrides=None,
) -> Union[bytes, Response]:
) -> Union[bytes, Response,dict]:
request = self._build_request("GET", path, headers, query_params, overrides)

timeout = self.timeout
Expand All @@ -124,6 +123,9 @@ def _execute_download_request(
stream=stream,
)

if not response.ok:
return _validate_response(response)

# If we stream an iterator for streaming the content, otherwise return the entire byte array
if stream:
return response
Expand Down

0 comments on commit 5922f8c

Please sign in to comment.