rename NetworkError to ConnectionError

This commit is contained in:
Bruno Windels 2020-04-19 19:05:12 +02:00
parent 8c5411cb7d
commit 8c56ac3e4f
8 changed files with 18 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import Platform from "../Platform.js"; import Platform from "../Platform.js";
import {HomeServerError, NetworkError} from "./error.js"; import {HomeServerError, ConnectionError} from "./error.js";
export class RateLimitingBackoff { export class RateLimitingBackoff {
constructor() { constructor() {
@ -88,7 +88,7 @@ export class SendScheduler {
// this can throw! // this can throw!
result = await this._doSend(request.sendCallback); result = await this._doSend(request.sendCallback);
} catch (err) { } catch (err) {
if (err instanceof NetworkError) { if (err instanceof ConnectionError) {
// we're offline, everybody will have // we're offline, everybody will have
// to re-request slots when we come back online // to re-request slots when we come back online
this._offline = true; this._offline = true;

View File

@ -81,7 +81,7 @@ export class SessionContainer {
this._loginFailure = LoginFailure.Unknown; this._loginFailure = LoginFailure.Unknown;
} }
this._status.set(LoadStatus.LoginFailure); this._status.set(LoadStatus.LoginFailure);
} else if (err instanceof NetworkError) { } else if (err instanceof ConnectionError) {
this._loginFailure = LoginFailure.Network; this._loginFailure = LoginFailure.Network;
this._status.set(LoadStatus.LoginFailure); this._status.set(LoadStatus.LoginFailure);
} else { } else {
@ -150,10 +150,10 @@ export class SessionContainer {
try { try {
await this._sync.start(); await this._sync.start();
} catch (err) { } catch (err) {
// swallow NetworkError here and continue, // swallow ConnectionError here and continue,
// as the reconnector above will call // as the reconnector above will call
// sync.start again to retry in this case // sync.start again to retry in this case
if (!(err instanceof NetworkError)) { if (!(err instanceof ConnectionError)) {
throw err; throw err;
} }
} }

View File

@ -15,5 +15,5 @@ export class HomeServerError extends Error {
export {AbortError} from "../utils/error.js"; export {AbortError} from "../utils/error.js";
export class NetworkError extends Error { export class ConnectionError extends Error {
} }

View File

@ -1,6 +1,6 @@
import { import {
HomeServerError, HomeServerError,
NetworkError, ConnectionError,
} from "./error.js"; } from "./error.js";
class RequestWrapper { class RequestWrapper {
@ -85,7 +85,7 @@ export default class HomeServerApi {
if (this._reconnector) { if (this._reconnector) {
wrapper.response().catch(err => { wrapper.response().catch(err => {
if (err instanceof NetworkError) { if (err instanceof ConnectionError) {
this._reconnector.onRequestFailed(this); this._reconnector.onRequestFailed(this);
} }
}); });

View File

@ -1,6 +1,6 @@
import createEnum from "../../utils/enum.js"; import createEnum from "../../utils/enum.js";
import {AbortError} from "../../utils/error.js"; import {AbortError} from "../../utils/error.js";
import {NetworkError} from "../error.js" import {ConnectionError} from "../error.js"
import ObservableValue from "../../observable/ObservableValue.js"; import ObservableValue from "../../observable/ObservableValue.js";
export const ConnectionStatus = createEnum( export const ConnectionStatus = createEnum(
@ -93,7 +93,7 @@ export class Reconnector {
this._versionsResponse = await versionsRequest.response(); this._versionsResponse = await versionsRequest.response();
this._setState(ConnectionStatus.Online); this._setState(ConnectionStatus.Online);
} catch (err) { } catch (err) {
if (err instanceof NetworkError) { if (err instanceof ConnectionError) {
this._setState(ConnectionStatus.Waiting); this._setState(ConnectionStatus.Waiting);
try { try {
await this._retryDelay.waitForRetry(); await this._retryDelay.waitForRetry();
@ -122,7 +122,7 @@ export function tests() {
response() { response() {
if (remainingFailures) { if (remainingFailures) {
remainingFailures -= 1; remainingFailures -= 1;
return Promise.reject(new NetworkError()); return Promise.reject(new ConnectionError());
} else { } else {
return Promise.resolve(42); return Promise.resolve(42);
} }

View File

@ -1,6 +1,6 @@
import { import {
AbortError, AbortError,
NetworkError ConnectionError
} from "../error.js"; } from "../error.js";
class RequestResult { class RequestResult {
@ -58,7 +58,7 @@ export default function fetchRequest(url, options) {
// //
// One could check navigator.onLine to rule out the first // One could check navigator.onLine to rule out the first
// but the 2 latter ones are indistinguishable from javascript. // but the 2 latter ones are indistinguishable from javascript.
throw new NetworkError(`${options.method} ${url}: ${err.message}`); throw new ConnectionError(`${options.method} ${url}: ${err.message}`);
} }
throw err; throw err;
}); });

View File

@ -1,6 +1,6 @@
import { import {
AbortError, AbortError,
NetworkError ConnectionError
} from "../error.js"; } from "../error.js";
class RequestLogItem { class RequestLogItem {
@ -24,7 +24,7 @@ class RequestLogItem {
this.end = performance.now(); this.end = performance.now();
this.error = { this.error = {
aborted: err instanceof AbortError, aborted: err instanceof AbortError,
network: err instanceof NetworkError, network: err instanceof ConnectionError,
message: err.message, message: err.message,
}; };
} }
@ -98,7 +98,7 @@ class ReplayRequestResult {
if (error.aborted || this._aborted) { if (error.aborted || this._aborted) {
throw new AbortError(error.message); throw new AbortError(error.message);
} else if (error.network) { } else if (error.network) {
throw new NetworkError(error.message); throw new ConnectionError(error.message);
} else { } else {
throw new Error(error.message); throw new Error(error.message);
} }

View File

@ -1,5 +1,5 @@
import SortedArray from "../../../observable/list/SortedArray.js"; import SortedArray from "../../../observable/list/SortedArray.js";
import {NetworkError} from "../../error.js"; import {ConnectionError} from "../../error.js";
import PendingEvent from "./PendingEvent.js"; import PendingEvent from "./PendingEvent.js";
function makeTxnId() { function makeTxnId() {
@ -52,7 +52,7 @@ export default class SendQueue {
console.log("keep sending?", this._amountSent, "<", this._pendingEvents.length); console.log("keep sending?", this._amountSent, "<", this._pendingEvents.length);
} }
} catch(err) { } catch(err) {
if (err instanceof NetworkError) { if (err instanceof ConnectionError) {
this._offline = true; this._offline = true;
} }
} finally { } finally {