Login: show a nice error when pointing to a bad Etebase server.

master
Tom Hacohen 4 years ago
parent d464040d8e
commit b93718a5cb

@ -12,11 +12,14 @@ import LoginForm from "./components/LoginForm";
import { login } from "./store/actions"; import { login } from "./store/actions";
import * as Etebase from "etebase";
import * as C from "./constants"; import * as C from "./constants";
import SignedPagesBadge from "./images/signed-pages-badge.svg"; import SignedPagesBadge from "./images/signed-pages-badge.svg";
import { useCredentials } from "./credentials"; import { useCredentials } from "./credentials";
import LoadingIndicator from "./widgets/LoadingIndicator"; import LoadingIndicator from "./widgets/LoadingIndicator";
import { startTask } from "./helpers";
export default function LoginGate() { export default function LoginGate() {
@ -29,11 +32,17 @@ export default function LoginGate() {
try { try {
setLoading(true); setLoading(true);
setFetchError(undefined); setFetchError(undefined);
const ret = login(username, password, serviceApiUrl); const etebase = await startTask((async () => {
await ret.payload; return await Etebase.Account.login(username, password, serviceApiUrl);
dispatch(ret); }));
dispatch(login(etebase));
} catch (e) { } catch (e) {
console.log(e);
if ((e instanceof Etebase.HTTPError) && (e.status === 404)) {
setFetchError(new Error("Etebase server not found: are you sure the server URL is correct?"));
} else {
setFetchError(e); setFetchError(e);
}
} finally { } finally {
setLoading(false); setLoading(false);
} }

@ -6,7 +6,6 @@ import { createAction as origCreateAction, ActionMeta } from "redux-actions";
import * as Etebase from "etebase"; import * as Etebase from "etebase";
import { SettingsType } from "./"; import { SettingsType } from "./";
import { startTask } from "../helpers";
type FunctionAny = (...args: any[]) => any; type FunctionAny = (...args: any[]) => any;
@ -28,17 +27,15 @@ export const resetKey = createAction(
export const logout = createAction( export const logout = createAction(
"LOGOUT", "LOGOUT",
async (etebase: Etebase.Account) => { async (etebase: Etebase.Account) => {
await etebase.logout(); // We don't wait on purpose, because we would like to logout and clear local data anyway
etebase.logout();
} }
); );
export const login = createAction( export const login = createAction(
"LOGIN", "LOGIN",
async (username: string, password: string, server: string | undefined) => { async (etebase: Etebase.Account) => {
return startTask((async () => {
const etebase = await Etebase.Account.login(username, password, server);
return etebase.save(); return etebase.save();
}));
} }
); );

Loading…
Cancel
Save