Skip to content

Commit

Permalink
Merge pull request #358 from 0x5e/fix/recoverable_error
Browse files Browse the repository at this point in the history
retry on error code -30001 and -9999
  • Loading branch information
merdok committed Oct 10, 2022
2 parents 94a8067 + 45feeec commit 38f9ca7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/protocol/MiioProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const PORT = 54321;
const HANDSHAKE_TIMEOUT = 5000;
const DEFAULT_TIMEOUT = 4000;
const DEFAULT_RETRIES = 2;
const RECOVERABLE_ERRORS = [-30001, -9999];

class MiioProtocol extends EventEmitter {
constructor(logger) {
Expand Down Expand Up @@ -348,7 +349,6 @@ class MiioProtocol extends EventEmitter {
resolve(res);
},
reject: err => {
resolved = true;
device._promises.delete(request.id);

if (!(err instanceof Error) && typeof err.code !== 'undefined') {
Expand All @@ -359,7 +359,15 @@ class MiioProtocol extends EventEmitter {
err = new Error(message);
err.code = code;
}

if (RECOVERABLE_ERRORS.includes(err.code)) {
this.logger.deepDebug(`(Protocol) ${address} <- Receving recoverable error: (${err.code}) ${err.message}, retries left: ${retriesLeft}`);
retry();
return false;
}

this.logger.deepDebug(`(Protocol) ${address} <- Error during send! (${err.code}) ${err.message} | Request: ${JSON.stringify(request)}`);
resolved = true;
reject(err);
},
};
Expand Down

0 comments on commit 38f9ca7

Please sign in to comment.