Skip to content

Commit

Permalink
improve csrf expiration error handling (#2695)
Browse files Browse the repository at this point in the history
* add message

* re run query on result set mount if there is session time out error
  • Loading branch information
Alanna Scott authored and mistercrunch committed May 1, 2017
1 parent 5fd0e7d commit 2d5beb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions superset/assets/javascripts/SqlLab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export function runQuery(query) {
} else if (msg === null) {
msg = `[${textStatus}] ${errorThrown}`;
}
if (msg.indexOf('The CSRF token is missing') > 0) {
msg = 'Your session timed out, please refresh your page and try again.';
}
dispatch(queryFailed(query, msg));
},
});
Expand Down
12 changes: 10 additions & 2 deletions superset/assets/javascripts/SqlLab/components/ResultSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class ResultSet extends React.PureComponent {
height: props.search ? props.height - RESULT_SET_CONTROLS_HEIGHT : props.height,
};
}
componentDidMount() {
// only do this the first time the component is rendered/mounted
this.reRunQueryIfSessionTimeoutErrorOnMount();
}
componentWillReceiveProps(nextProps) {
// when new results comes in, save them locally and clear in store
if (this.props.cache && (!nextProps.query.cached)
Expand All @@ -53,7 +57,6 @@ export default class ResultSet extends React.PureComponent {
this.fetchResults(nextProps.query);
}
}

getControls() {
if (this.props.search || this.props.visualize || this.props.csv) {
let csvButton;
Expand Down Expand Up @@ -132,7 +135,12 @@ export default class ResultSet extends React.PureComponent {
reFetchQueryResults(query) {
this.props.actions.reFetchQueryResults(query);
}

reRunQueryIfSessionTimeoutErrorOnMount() {
const { query } = this.props;
if (query.errorMessage && query.errorMessage.indexOf('session timed out') > 0) {
this.props.actions.runQuery(query, true);
}
}
render() {
const query = this.props.query;
const results = query.results;
Expand Down

0 comments on commit 2d5beb1

Please sign in to comment.