forked from mystiq/hydrogen-web
dont emit error when aborting request when stopping sync
This commit is contained in:
parent
bff0161a05
commit
35648d31b9
2 changed files with 13 additions and 3 deletions
|
@ -1,4 +1,7 @@
|
||||||
import {HomeServerError} from "./error.js";
|
import {
|
||||||
|
HomeServerError,
|
||||||
|
RequestAbortError
|
||||||
|
} from "./error.js";
|
||||||
|
|
||||||
class RequestWrapper {
|
class RequestWrapper {
|
||||||
constructor(promise, controller) {
|
constructor(promise, controller) {
|
||||||
|
@ -58,6 +61,11 @@ export default class HomeServerApi {
|
||||||
throw new HomeServerError(method, url, await response.json())
|
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);
|
return new RequestWrapper(promise, controller);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,11 @@ export default class Sync extends EventEmitter {
|
||||||
console.log(`starting sync request with since ${syncToken} ...`);
|
console.log(`starting sync request with since ${syncToken} ...`);
|
||||||
syncToken = await this._syncRequest(syncToken, INCREMENTAL_TIMEOUT);
|
syncToken = await this._syncRequest(syncToken, INCREMENTAL_TIMEOUT);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("stopping sync because of error");
|
|
||||||
this._isSyncing = false;
|
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");
|
this.emit("stopped");
|
||||||
|
|
Loading…
Reference in a new issue