Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors on Group Members, Group Data Sources and User Profile pages #3564

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/app/components/items-list/ItemsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export function wrap(WrappedComponent, itemsSource, stateStorage) {
this.state.update();
}

componentWillUnmount() {
itemsSource.onBeforeUpdate = () => {};
itemsSource.onAfterUpdate = () => {};
itemsSource.onError = () => {};
}

// eslint-disable-next-line class-methods-use-this
getState({ isLoaded, totalCount, pageItems, ...rest }) {
const params = {
Expand Down
12 changes: 6 additions & 6 deletions client/app/components/items-list/classes/ItemsSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export class ItemsSource {
return this._afterUpdate();
})
.catch((error) => {
// ANGULAR_REMOVE_ME This code is related to Angular's HTTP services
if (error.status && error.data) {
error = new PromiseRejectionError(error.data.message);
}
this.handleError(error);
})
));
Expand Down Expand Up @@ -132,11 +128,15 @@ export class ItemsSource {

update = () => this._changed();

handleError(error) {
handleError = (error) => {
if (isFunction(this.onError)) {
// ANGULAR_REMOVE_ME This code is related to Angular's HTTP services
if (error.status && error.data) {
error = new PromiseRejectionError(error);
}
this.onError(error);
}
}
};
}

export class ResourceItemsSource extends ItemsSource {
Expand Down
12 changes: 8 additions & 4 deletions client/app/pages/groups/GroupDataSources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ class GroupDataSources extends React.Component {
];

componentDidMount() {
Group.get({ id: this.groupId }).$promise.then((group) => {
this.group = group;
this.forceUpdate();
});
Group.get({ id: this.groupId }).$promise
.then((group) => {
this.group = group;
this.forceUpdate();
})
.catch((error) => {
this.props.controller.handleError(error);
});
}

removeGroupDataSource = (datasource) => {
Expand Down
12 changes: 8 additions & 4 deletions client/app/pages/groups/GroupMembers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ class GroupMembers extends React.Component {
];

componentDidMount() {
Group.get({ id: this.groupId }).$promise.then((group) => {
this.group = group;
this.forceUpdate();
});
Group.get({ id: this.groupId }).$promise
.then((group) => {
this.group = group;
this.forceUpdate();
})
.catch((error) => {
this.props.controller.handleError(error);
});
}

removeGroupMember = (event, user) => Group.removeMember({ id: this.groupId, userId: user.id }).$promise
Expand Down
20 changes: 19 additions & 1 deletion client/app/pages/users/UserProfile.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { react2angular } from 'react2angular';

import { EmailSettingsWarning } from '@/components/EmailSettingsWarning';
Expand All @@ -10,17 +11,34 @@ import { User } from '@/services/user';
import settingsMenu from '@/services/settingsMenu';
import { $route } from '@/services/ng';
import { currentUser } from '@/services/auth';
import PromiseRejectionError from '@/lib/promise-rejection-error';
import './settings.less';

class UserProfile extends React.Component {
static propTypes = {
onError: PropTypes.func,
};

static defaultProps = {
onError: () => {},
};

constructor(props) {
super(props);
this.state = { user: null };
}

componentDidMount() {
const userId = $route.current.params.userId || currentUser.id;
User.get({ id: userId }, user => this.setState({ user: User.convertUserInfo(user) }));
User.get({ id: userId }).$promise
.then(user => this.setState({ user: User.convertUserInfo(user) }))
.catch((error) => {
// ANGULAR_REMOVE_ME This code is related to Angular's HTTP services
if (error.status && error.data) {
error = new PromiseRejectionError(error);
}
this.props.onError(error);
});
}

render() {
Expand Down