From bce6e7824562572ad992e97c5e80ac7cd22db652 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 27 Mar 2020 18:38:35 +0100 Subject: [PATCH] hopefully fix reconnect on polling error --- src/index.ts | 3 ++- src/skype.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4fd15b6..193b903 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; } diff --git a/src/skype.ts b/src/skype.ts index df14d8d..04dd319 100644 --- a/src/skype.ts +++ b/src/skype.ts @@ -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();