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 NetworkError extends Error {
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
HomeServerError,
|
||||
RequestAbortError
|
||||
RequestAbortError,
|
||||
NetworkError
|
||||
} from "./error.js";
|
||||
|
||||
class RequestWrapper {
|
||||
@ -62,10 +63,18 @@ export default class HomeServerApi {
|
||||
}
|
||||
}
|
||||
}, err => {
|
||||
switch (err.name) {
|
||||
case "AbortError": throw new RequestAbortError();
|
||||
default: throw err; //new Error(`Unrecognized DOMException: ${err.name}`);
|
||||
}
|
||||
if (err.name === "AbortError") {
|
||||
throw new RequestAbortError();
|
||||
} 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user