Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate attachment response and throw error #396

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nylas/handler/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def _validate_response(response: Response) -> dict:

return json

def _validate_download_response(response:Response) -> Union[bytes, Response, dict]:
if response.ok:
return response.content
return _validate_response(response)

def _build_query_params(base_url: str, query_params: dict = None) -> str:
query_param_parts = []
Expand Down Expand Up @@ -126,9 +130,9 @@ def _execute_download_request(

# If we stream an iterator for streaming the content, otherwise return the entire byte array
if stream:
return response
return response if response.ok else _validate_response(response)

return response.content if response.content else None
return _validate_download_response(response) if response.content else None
AaronDDM marked this conversation as resolved.
Show resolved Hide resolved
except requests.exceptions.Timeout as exc:
raise NylasSdkTimeoutError(url=request["url"], timeout=timeout) from exc

Expand Down
Loading