From 35648d31b9285349660da57f46222ba138d1c4bd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Sun, 10 Feb 2019 21:40:11 +0100 Subject: [PATCH] dont emit error when aborting request when stopping sync --- src/matrix/hs-api.js | 10 +++++++++- src/matrix/sync.js | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/matrix/hs-api.js b/src/matrix/hs-api.js index 828f91ca..75fe4261 100644 --- a/src/matrix/hs-api.js +++ b/src/matrix/hs-api.js @@ -1,4 +1,7 @@ -import {HomeServerError} from "./error.js"; +import { + HomeServerError, + RequestAbortError +} from "./error.js"; class RequestWrapper { constructor(promise, controller) { @@ -58,6 +61,11 @@ export default class HomeServerApi { throw new HomeServerError(method, url, await response.json()) } } + }, err => { + switch (err.name) { + case "AbortError": throw new RequestAbortError(); + default: throw new Error(`Unrecognized DOMException: ${err.name}`); + } }); return new RequestWrapper(promise, controller); } diff --git a/src/matrix/sync.js b/src/matrix/sync.js index 538fb8ec..91d36d68 100644 --- a/src/matrix/sync.js +++ b/src/matrix/sync.js @@ -55,9 +55,11 @@ export default class Sync extends EventEmitter { console.log(`starting sync request with since ${syncToken} ...`); syncToken = await this._syncRequest(syncToken, INCREMENTAL_TIMEOUT); } catch (err) { - console.warn("stopping sync because of error"); this._isSyncing = false; - this.emit("error", err); + if (!(err instanceof RequestAbortError)) { + console.warn("stopping sync because of error"); + this.emit("error", err); + } } } this.emit("stopped");