mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
Improve API error handling.
This commit is contained in:
@ -56,7 +56,7 @@ class ApplicationEditPage extends React.Component {
|
||||
OrganizationBackend.getOrganizations("admin")
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
organizations: res,
|
||||
organizations: (res.msg === undefined) ? res : [],
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -277,19 +277,19 @@ class ApplicationEditPage extends React.Component {
|
||||
let application = Setting.deepCopy(this.state.application);
|
||||
ApplicationBackend.updateApplication(this.state.application.owner, this.state.applicationName, application)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.msg === "") {
|
||||
Setting.showMessage("success", `Successfully saved`);
|
||||
this.setState({
|
||||
applicationName: this.state.application.name,
|
||||
});
|
||||
this.props.history.push(`/applications/${this.state.application.name}`);
|
||||
} else {
|
||||
Setting.showMessage("error", `failed to save: server side failure`);
|
||||
Setting.showMessage("error", res.msg);
|
||||
this.updateApplicationField('name', this.state.applicationName);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `failed to save: ${error}`);
|
||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -104,19 +104,19 @@ class OrganizationEditPage extends React.Component {
|
||||
let organization = Setting.deepCopy(this.state.organization);
|
||||
OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.msg === "") {
|
||||
Setting.showMessage("success", `Successfully saved`);
|
||||
this.setState({
|
||||
organizationName: this.state.organization.name,
|
||||
});
|
||||
this.props.history.push(`/organizations/${this.state.organization.name}`);
|
||||
} else {
|
||||
Setting.showMessage("error", `failed to save: server side failure`);
|
||||
Setting.showMessage("error", res.msg);
|
||||
this.updateOrganizationField('name', this.state.organizationName);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `failed to save: ${error}`);
|
||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -143,19 +143,19 @@ class ProviderEditPage extends React.Component {
|
||||
let provider = Setting.deepCopy(this.state.provider);
|
||||
ProviderBackend.updateProvider(this.state.provider.owner, this.state.providerName, provider)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.msg === "") {
|
||||
Setting.showMessage("success", `Successfully saved`);
|
||||
this.setState({
|
||||
providerName: this.state.provider.name,
|
||||
});
|
||||
this.props.history.push(`/providers/${this.state.provider.name}`);
|
||||
} else {
|
||||
Setting.showMessage("error", `failed to save: server side failure`);
|
||||
Setting.showMessage("error", res.msg);
|
||||
this.updateProviderField('name', this.state.providerName);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `failed to save: ${error}`);
|
||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -144,19 +144,19 @@ class TokenEditPage extends React.Component {
|
||||
let token = Setting.deepCopy(this.state.token);
|
||||
TokenBackend.updateToken(this.state.token.owner, this.state.tokenName, token)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.msg === "") {
|
||||
Setting.showMessage("success", `Successfully saved`);
|
||||
this.setState({
|
||||
tokenName: this.state.token.name,
|
||||
});
|
||||
this.props.history.push(`/tokens/${this.state.token.name}`);
|
||||
} else {
|
||||
Setting.showMessage("error", `failed to save: server side failure`);
|
||||
Setting.showMessage("error", res.msg);
|
||||
this.updateTokenField('name', this.state.tokenName);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `failed to save: ${error}`);
|
||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class UserEditPage extends React.Component {
|
||||
OrganizationBackend.getOrganizations("admin")
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
organizations: res,
|
||||
organizations: (res.msg === undefined) ? res : [],
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -266,7 +266,7 @@ class UserEditPage extends React.Component {
|
||||
let user = Setting.deepCopy(this.state.user);
|
||||
UserBackend.updateUser(this.state.organizationName, this.state.userName, user)
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.msg === "") {
|
||||
Setting.showMessage("success", `Successfully saved`);
|
||||
this.setState({
|
||||
organizationName: this.state.user.owner,
|
||||
@ -277,13 +277,13 @@ class UserEditPage extends React.Component {
|
||||
this.props.history.push(`/users/${this.state.user.owner}/${this.state.user.name}`);
|
||||
}
|
||||
} else {
|
||||
Setting.showMessage("error", `failed to save: server side failure`);
|
||||
Setting.showMessage("error", res.msg);
|
||||
this.updateUserField('owner', this.state.organizationName);
|
||||
this.updateUserField('name', this.state.userName);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `failed to save: ${error}`);
|
||||
Setting.showMessage("error", `failed to connect to server: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user