mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 19:31:26 +00:00
wrap login call in try/catch for error handling
This commit is contained in:
parent
e0cc7ba3c3
commit
55512a2eae
1 changed files with 30 additions and 26 deletions
|
@ -160,38 +160,42 @@ export class Login extends Component<any, State> {
|
||||||
if (username_or_email && password) {
|
if (username_or_email && password) {
|
||||||
i.setState({ loginRes: { state: "loading" } });
|
i.setState({ loginRes: { state: "loading" } });
|
||||||
|
|
||||||
const loginRes = await HttpService.client.login({
|
try {
|
||||||
username_or_email,
|
const loginRes = await HttpService.client.login({
|
||||||
password,
|
username_or_email,
|
||||||
totp_2fa_token,
|
password,
|
||||||
});
|
totp_2fa_token,
|
||||||
switch (loginRes.state) {
|
});
|
||||||
case "failed": {
|
switch (loginRes.state) {
|
||||||
if (loginRes.msg === "missing_totp_token") {
|
case "failed": {
|
||||||
i.setState({ showTotp: true });
|
if (loginRes.msg === "missing_totp_token") {
|
||||||
toast(i18n.t("enter_two_factor_code"), "info");
|
i.setState({ showTotp: true });
|
||||||
|
toast(i18n.t("enter_two_factor_code"), "info");
|
||||||
|
}
|
||||||
|
|
||||||
|
i.setState({ loginRes: { state: "empty" } });
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i.setState({ loginRes: { state: "empty" } });
|
case "success": {
|
||||||
break;
|
UserService.Instance.login(loginRes.data);
|
||||||
}
|
const site = await HttpService.client.getSite({
|
||||||
|
auth: myAuth(),
|
||||||
|
});
|
||||||
|
|
||||||
case "success": {
|
if (site.state === "success") {
|
||||||
UserService.Instance.login(loginRes.data);
|
UserService.Instance.myUserInfo = site.data.my_user;
|
||||||
const site = await HttpService.client.getSite({
|
}
|
||||||
auth: myAuth(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (site.state === "success") {
|
i.props.history.action === "PUSH"
|
||||||
UserService.Instance.myUserInfo = site.data.my_user;
|
? i.props.history.back()
|
||||||
|
: i.props.history.replace("/");
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i.props.history.action === "PUSH"
|
|
||||||
? i.props.history.back()
|
|
||||||
: i.props.history.replace("/");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
i.setState({ loginRes: { state: "failed", msg: error.message } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue