Skip to content

Conversation

@ajay-k
Copy link
Contributor

@ajay-k ajay-k commented Apr 17, 2025

Description

This pull request fixes an issue where request timeout overrides were inconsistently handled compared to the timeout set in the constructor. Previously, the timeout in the constructor was treated as seconds and converted to milliseconds, while timeout in request overrides was incorrectly treated directly as milliseconds.

The changes in this PR ensure that:
Consistent behavior with backward compatibility:

  • Values < 1000 are treated as seconds and converted to milliseconds internally (new behavior)
  • Values ≥ 1000 are still treated as milliseconds for backward compatibility
  • A deprecation warning is shown for values ≥ 1000, pointing users toward using seconds in the next major release

Correct error reporting:
Error messages correctly display the actual timeout value that was used for the request (in seconds)
Previously it would always show the client timeout regardless of which timeout was used
These changes maintain API compatibility while fixing the inconsistent behavior, providing a clear migration path for users. After the next major version, all timeout values will be treated consistently as seconds.

  • Starts to address #633
  • Jira Ticket
  • We'll need to address the change and remove the warning message in the next release, this fix signals to the customer to prepare for this change and adds a warning message

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.

@ajay-k
Copy link
Contributor Author

ajay-k commented Apr 18, 2025

After discussing this with @AaronDDM we both agree implementing this right away would be a breaking change, we're going to handle this by:

  • Figuring out if the customer is using milliseconds and add a warning to let customers know it's being deprecated in next major release and to use seconds instead
  • Had Cursor AI write some tests for me to make sure it worked as expected:

🔍 TEST 1: Small timeout value (< 1000, treated as seconds)
Making request with override timeout of 5 seconds...
(node:84791) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
✅ Request succeeded with small timeout value
First thread ID: 19639fa7f8a200b8

🔍 TEST 2: Large timeout value (≥ 1000, treated as milliseconds)
Making request with override timeout of 3000 milliseconds...
✅ Request succeeded with large timeout value
First thread ID: 19639fa7f8a200b8
✅ Deprecation warning shown as expected:
"DEPRECATED: Providing timeout in milliseconds via request overrides is deprecated and will be removed in the next major release. Please use seconds instead."

🔍 TEST 3: Force timeout error with very small value (0.001 seconds)
Making request with tiny timeout to force an error...
✅ Timeout error occurred as expected
Error details:
Type: NylasSdkTimeoutError
Message: Nylas SDK timed out before receiving a response from the server.
Timeout: 0.001 seconds
URL: https://api.us.nylas.com/v3/grants/8eab7c11-9143-406d-928f-57b16ca45d1e/threads?limit=1

src/apiClient.ts Outdated
Comment on lines 165 to 168
// eslint-disable-next-line no-console
console.warn(
'DEPRECATED: Providing timeout in milliseconds via request overrides is deprecated and will be removed in the next major release. Please use seconds instead.'
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ajay-k let's remove this console warn message and instead add a @deprecated [message here] to the options.overrides.timeout property defined in the OverridableNylasConfig interface/type. So we'll just use typescript to notify of this impending deprecation.

Also update the CHANGELOG.md to call out this deprecation.

Finally, you have some github actions failing that need to be resolved.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @AaronDDM made some changes you suggested, can you review and lmk if it looks good to you as well?

@ajay-k ajay-k merged commit 6feced3 into main May 1, 2025
5 checks passed
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.

3 participants