improve admin page error handling

This commit is contained in:
Tao Bror Bojlén 2019-08-02 22:55:26 +03:00
parent cc95d19ee8
commit a39887856d
No known key found for this signature in database
GPG key ID: C6EC7AAB905F9E6F
2 changed files with 15 additions and 3 deletions

View file

@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Clarify that the admin page only works for Mastodon and Pleroma instances.
### Changed
### Deprecated
@ -19,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed some instances being duplicated (due to un-normalized data).
- Fixed mobile instance view erroring for uncrawled instances.
- Improved error handling in admin login page.
### Security

View file

@ -76,6 +76,9 @@ class LoginScreen extends React.PureComponent<{}, ILoginScreenState> {
<p className={Classes.RUNNING_TEXT}>
To manage how fediverse.space interacts with your instance, you must be the instance admin.
</p>
<p className={Classes.RUNNING_TEXT}>
Note that it's currently only possible to administrate Mastodon and Pleroma instances.
</p>
<FormContainer error={this.state.error}>{content}</FormContainer>
</Page>
);
@ -172,7 +175,12 @@ class LoginScreen extends React.PureComponent<{}, ILoginScreenState> {
}
getFromApi(`admin/login/${domain}`)
.then(response => {
this.setState({ loginTypes: response, isGettingLoginTypes: false });
if ("error" in response || "errors" in response) {
// Go to catch() below
throw new Error();
} else {
this.setState({ loginTypes: response, isGettingLoginTypes: false });
}
})
.catch(() => {
this.setState({ error: true });
@ -183,8 +191,9 @@ class LoginScreen extends React.PureComponent<{}, ILoginScreenState> {
this.setState({ isSendingLoginRequest: true, selectedLoginType: type });
postToApi("admin/login", { domain: this.state.loginTypes!.domain, type })
.then(response => {
if ("error" in response) {
this.setState({ isSendingLoginRequest: false, error: true });
if ("error" in response || "errors" in response) {
// Go to catch() below
throw new Error();
} else {
this.setState({ isSendingLoginRequest: false });
}