@vielhuber/wahelper 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/wahelper-daemon.js +17 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielhuber/wahelper",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Lightweight whatsapp integration layer.",
5
5
  "main": "wahelper.js",
6
6
  "files": [
@@ -651,18 +651,23 @@ export default class wahelperDaemon {
651
651
  return;
652
652
  }
653
653
 
654
- // reconnect on all other disconnect reasons with exponential backoff
655
- let reason =
656
- DisconnectReason && statusCode
657
- ? Object.keys(DisconnectReason).find(k => DisconnectReason[k] === statusCode)
658
- : null;
659
- this.lastError = {
660
- source: 'disconnect',
661
- message:
662
- 'connection closed' +
663
- (reason ? ' (' + reason + ')' : statusCode ? ' (statusCode=' + statusCode + ')' : ''),
664
- at: Date.now()
665
- };
654
+ // a disconnect right after a pairing failure is just
655
+ // the symptom — keep the more specific upstream
656
+ // reason (e.g. "rate-overlimit") instead of burying
657
+ // it under a generic "connectionLost"
658
+ if (this.lastError?.source !== 'pairing') {
659
+ let reason =
660
+ DisconnectReason && statusCode
661
+ ? Object.keys(DisconnectReason).find(k => DisconnectReason[k] === statusCode)
662
+ : null;
663
+ this.lastError = {
664
+ source: 'disconnect',
665
+ message:
666
+ 'connection closed' +
667
+ (reason ? ' (' + reason + ')' : statusCode ? ' (statusCode=' + statusCode + ')' : ''),
668
+ at: Date.now()
669
+ };
670
+ }
666
671
  this.consecutiveFailures++;
667
672
  // first 3 attempts recover network blips fast (1s/2s/4s),
668
673
  // after that back off to 15min so a persistent failure