dont emit error when aborting request when stopping sync

This commit is contained in:
Bruno Windels 2019-02-10 21:40:11 +01:00
parent bff0161a05
commit 35648d31b9
2 changed files with 13 additions and 3 deletions

View file

@ -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);
}

View file

@ -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");