hopefully fix reconnect on polling error

This commit is contained in:
Sorunome 2020-03-27 18:38:35 +01:00
parent 4cdddc4996
commit bce6e78245
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 12 additions and 6 deletions

View File

@ -126,7 +126,8 @@ async function run() {
data.state = client.getState;
await client.disconnect();
} catch (err) {
log.verbose("Failed to log in as new user, perhaps the password is worng?", err);
log.verbose("Failed to log in as new user, perhaps the password is worng?");
log.silly(err);
retData.error = "Username or password wrong";
return retData;
}

View File

@ -19,6 +19,7 @@ import { Client } from "./client";
import * as skypeHttp from "skype-http";
import { Contact as SkypeContact } from "skype-http/dist/lib/types/contact";
import { NewMediaMessage as SkypeNewMediaMessage } from "skype-http/dist/lib/interfaces/api/api";
import { UnexpectedHttpStatusError } from "skype-http/dist/lib/errors";
import * as decodeHtml from "decode-html";
import * as escapeHtml from "escape-html";
import { MatrixMessageParser } from "./matrixmessageparser";
@ -183,12 +184,16 @@ export class Skype {
});
const MINUTE = 60000;
client.on("error", async (err: Error) => {
await this.puppet.sendStatusMessage(puppetId, "Error: " + err);
await this.puppet.sendStatusMessage(puppetId, "Reconnecting in a minute... ");
setTimeout(async () => {
log.error("Error when polling");
log.error(err);
if (err.name === "UnexpectedHttpStatus") {
await this.puppet.sendStatusMessage(puppetId, "Error: " + err);
await this.puppet.sendStatusMessage(puppetId, "Reconnecting in a minute... ");
await this.stopClient(puppetId);
await this.startClient(puppetId);
}, MINUTE);
setTimeout(async () => {
await this.startClient(puppetId);
}, MINUTE);
}
});
try {
await client.connect();