diff --git a/lib/protocol/MiioProtocol.js b/lib/protocol/MiioProtocol.js index 94a2843..4d65444 100644 --- a/lib/protocol/MiioProtocol.js +++ b/lib/protocol/MiioProtocol.js @@ -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) { @@ -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') { @@ -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); }, };