Skip to content

Commit

Permalink
Stop polling list of bundles if network error appears
Browse files Browse the repository at this point in the history
  • Loading branch information
jgruica committed Aug 31, 2020
1 parent 3b6dfd1 commit e2c8046
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions kotsadm/web/src/components/troubleshoot/GenerateSupportBundle.jsx
Expand Up @@ -32,7 +32,8 @@ class GenerateSupportBundle extends React.Component {
supportBundles: [],
listSupportBundlesJob: new Repeater(),
errorMsg: "",
displayErrorModal: false
displayErrorModal: false,
networkErr: false
};
}

Expand All @@ -51,10 +52,11 @@ class GenerateSupportBundle extends React.Component {
this.state.listSupportBundlesJob.stop();
}

componentDidUpdate(lastProps) {
componentDidUpdate(lastProps, lastState) {
const { watch, history } = this.props;
const { totalBundles, loadingSupportBundles, supportBundles } = this.state;
const { totalBundles, loadingSupportBundles, supportBundles, networkErr } = this.state;
const clusters = watch.downstream;

if (watch !== lastProps.watch && clusters) {
const watchClusters = clusters.map(c => c.cluster);
const NEW_ADDED_CLUSTER = { title: NEW_CLUSTER };
Expand All @@ -76,11 +78,20 @@ class GenerateSupportBundle extends React.Component {
history.push(`/app/${watch.slug}/troubleshoot/analyze/${bundle.id}`);
}
}

if (networkErr !== lastState.networkErr) {
if (networkErr) {
this.state.listSupportBundlesJob.stop();
} else {
this.state.listSupportBundlesJob.start(this.listSupportBundles, 2000);
return;
}
}
}

listSupportBundles = () => {
return new Promise((resolve, reject) => {
this.setState({ loadingSupportBundles: true, errorMsg: "", displayErrorModal: false });
this.setState({ loadingSupportBundles: true, errorMsg: "", displayErrorModal: false, networkErr: false });

fetch(`${window.env.API_ENDPOINT}/troubleshoot/app/${this.props.watch?.slug}/supportbundles`, {
headers: {
Expand All @@ -91,22 +102,23 @@ class GenerateSupportBundle extends React.Component {
})
.then(async (res) => {
if (!res.ok) {
this.setState({ loadingSupportBundles: false, errorMsg: `Unexpected status code: ${res.status}`, displayErrorModal: true });
this.setState({ loadingSupportBundles: false, errorMsg: `Unexpected status code: ${res.status}`, displayErrorModal: true, networkErr: false });
return;
}
const response = await res.json();
this.setState({
supportBundles: response.supportBundles,
loadingSupportBundles: false,
errorMsg: "",
displayErrorModal: false
displayErrorModal: false,
networkErr: false
});

resolve();
})
.catch((err) => {
console.log(err)
this.setState({ loadingSupportBundles: false, errorMsg: err ? err.message : "Something went wrong, please try again.", displayErrorModal: true });
this.setState({ loadingSupportBundles: false, errorMsg: err ? err.message : "Something went wrong, please try again.", displayErrorModal: true, networkErr: true });
reject(err);
});
});
Expand Down

0 comments on commit e2c8046

Please sign in to comment.