Skip to content

Commit

Permalink
[Bug fix] Handle errors on Group members, Group datasources and User …
Browse files Browse the repository at this point in the history
…profile pages (#3564)
  • Loading branch information
kravets-levko authored Mar 10, 2019
1 parent 5dc74e1 commit 4cfa26a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
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

0 comments on commit 4cfa26a

Please sign in to comment.