mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
throw NetworkError from HomeServerApi
This commit is contained in:
parent
f3034800ae
commit
049e70e312
@ -9,5 +9,7 @@ export class StorageError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class RequestAbortError extends Error {
|
export class RequestAbortError extends Error {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
export class NetworkError extends Error {
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
HomeServerError,
|
HomeServerError,
|
||||||
RequestAbortError
|
RequestAbortError,
|
||||||
|
NetworkError
|
||||||
} from "./error.js";
|
} from "./error.js";
|
||||||
|
|
||||||
class RequestWrapper {
|
class RequestWrapper {
|
||||||
@ -62,10 +63,18 @@ export default class HomeServerApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, err => {
|
}, err => {
|
||||||
switch (err.name) {
|
if (err.name === "AbortError") {
|
||||||
case "AbortError": throw new RequestAbortError();
|
throw new RequestAbortError();
|
||||||
default: throw err; //new Error(`Unrecognized DOMException: ${err.name}`);
|
} else if (err instanceof TypeError) {
|
||||||
}
|
// Network errors are reported as TypeErrors, see
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
|
||||||
|
// this can either mean user is offline, server is offline, or a CORS error (server misconfiguration).
|
||||||
|
//
|
||||||
|
// One could check navigator.onLine to rule out the first
|
||||||
|
// but the 2 later ones are indistinguishable from javascript.
|
||||||
|
throw new NetworkError(err.message);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
return new RequestWrapper(promise, controller);
|
return new RequestWrapper(promise, controller);
|
||||||
}
|
}
|
||||||
@ -92,4 +101,4 @@ export default class HomeServerApi {
|
|||||||
"password": password
|
"password": password
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user