-
Notifications
You must be signed in to change notification settings - Fork 5
Improve timeout handling #20
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances timeout handling by retrying transient errors in the API module, cleans up unused dependencies, updates test defaults, and sets up Mocha as the test runner.
- Added
_requestwrapper inopen_garage_api.jsto retry onECONNRESETandETIMEDOUT - Updated test defaults to use
*Secs * 1000for poll frequency and open/close duration - Removed unused
request-promise-nativeimport inopen_garage.jsand changed the npmtestscript to run Mocha
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/open_garage_test.js | Adjusted default timing values to use seconds-based settings × 1000 |
| package.json | Updated "test" script to invoke mocha |
| lib/open_garage_api.js | Introduced http.Agent and retry logic for transient timeout errors |
| lib/open_garage.js | Removed unused request-promise-native import comment |
| let pollFrequencyMs = OpenGarageModule.defaults.pollFrequencyMs | ||
| var openDurationMs = OpenGarageModule.defaults.openDurationMs | ||
| let pollFrequencyMs = OpenGarageModule.defaults.pollFrequencySecs * 1000 | ||
| var openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 |
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The declaration uses var while pollFrequencyMs uses let. Consider using let or const for consistency and block scoping.
| var openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 | |
| let openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 |
| @@ -1,4 +1,4 @@ | |||
| const request = require("request-promise-native") | |||
| // request-promise-native was previously required here but never used | |||
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Remove this commented-out import to clean up the code and avoid confusion, as it's no longer used.
| // request-promise-native was previously required here but never used |
| if (retries > 0 && err.cause) { | ||
| if (err.cause.code === 'ECONNRESET' || err.cause.code === 'ETIMEDOUT') { | ||
| log(`Transient ${err.cause.code} error, retrying request`) | ||
| return this._request(options, retries - 1) |
Copilot
AI
Jun 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Retries occur immediately without delay. Consider adding a short delay (e.g., using setTimeout) between retries to avoid rapid-fire requests.
| return this._request(options, retries - 1) | |
| return new Promise((resolve) => { | |
| setTimeout(() => resolve(this._request(options, retries - 1)), 100); | |
| }); |
Summary
OpenGarageApiopen_garage.jsnpm testTesting
npm test(fails: Service.OccupancySensor is not a constructor)https://chatgpt.com/codex/tasks/task_e_684380276384832cb099697ad6529ff7