Skip to content

Conversation

samuelpx
Copy link
Contributor

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

…es-html-fastly-empty-etc-stemming-from-500-s
…es-html-fastly-empty-etc-stemming-from-500-s
"""

request_id: str
request_id: Optional[str]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is ever optional for our API effors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll correct this!

self.headers: CaseInsensitiveDict = headers


class NylasNetworkError(AbstractNylasSdkError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we actually utilizing this new error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nowhere yet, the idea is that it will replace the proposed non-json handling implementation in the future, we currently raise a NylasApiError to keep backwards compatibility as a priority, let me know if we should just use this instead.

Copy link

playerzero-ai bot commented Aug 28, 2025

Pull Request Summary

  • Error Handling Enhancements:

    • Made certain attributes optional in error classes to allow more flexible error handling.
    • Introduced a new NylasNetworkError class to better handle non-JSON responses, capturing additional error details like raw_body and flow_id.
  • HTTP Client Improvements:

    • Enhanced error messages for non-JSON responses with status codes 400 or higher, including a preview of the response body and Fastly flow ID.
    • Refactored exception handling for OAuth and API errors for improved code readability and maintainability.
    • Made minor cosmetic changes to method signatures without affecting functionality.
  • Testing Enhancements:

    • Added tests for various HTTP error scenarios, including non-JSON responses, empty responses, and different content types.
    • Focused on improving error handling for HTTP status codes like 500, 502, 503, and 504, with and without "flow_id" headers.
    • Ensured the system can handle a range of non-JSON response types and edge cases, enhancing the reliability and error reporting of the HTTP client.

Functional Tests

  • Verify that non-JSON responses with status codes 400 or higher include a preview of the response body and Fastly flow ID in the error message.
  • Test the handling of a 500 error with an HTML response, ensuring the flow ID is extracted from headers if present.
  • Check the error message clarity for a 502 error with a plain text response.
  • Ensure successful handling of a 200 response with non-JSON content, verifying correct processing of response headers.
  • Test error detection for a 500 error with an empty response body.
  • Verify that long non-JSON responses are truncated in error messages for readability.
  • Check error handling when specific headers like a flow ID are present, ensuring they are included in error messages.
  • Ensure proper error reporting for scenarios missing a flow ID header.
  • Validate error handling consistency across different content types (HTML, plain text, XML, CSS) in 500 error responses.

Files Changed

File Name Summary
nylas/models/errors.py Made request_id, status_code, and headers optional in error classes. Added NylasNetworkError for non-JSON error responses with extra attributes (raw_body, flow_id) to improve network error reporting.
nylas/handler/http_client.py Enhanced error handling for non-JSON responses with status ≥400 by including response preview and Fastly flow ID. Refactored OAuth and API error exception raising for readability. Minor formatting fix in _execute_download_request signature. No changes to query parameter building.
tests/handler/test_http_client.py Added tests covering non-JSON error responses (500, 502, 503, 504), success with non-JSON, empty and long responses, and various content types to improve HTTP client error handling and reporting robustness.

View more in PlayerZero
updated: Aug 28 @ 03:27 AM UTC

…es-html-fastly-empty-etc-stemming-from-500-s
…es-html-fastly-empty-etc-stemming-from-500-s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants