Skip to content

Commit

Permalink
feat(error): Revert lists if error happens
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovicnemanja committed Dec 19, 2024
1 parent 224fb48 commit 1df1d46
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions client/components/ContentLists/Manual/Manual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,24 @@ class Manual extends React.Component {
},
}).then((response) => {
const ninjs = this.props.publisher.publishSuperdeskArticle('new', response.export[item_id]).then(async (response) => {
const article_id = await this.attemptFetch(10, item_id);
resolve(article_id);
try {
const article_id = await this.attemptFetch(10, item_id);
return resolve(article_id);
} catch (error) {
return reject(error);
}
});
});
});
}

attemptFetch = async (tries = 10, code) => {
if (tries === 0) {
return this.props.api.notify.error(
this.props.api.notify.error(
"Adding article to the content list failed, please try again. If the problem persists, please contact support."
);

throw new Error('Failed to fetch article');
}

try {
Expand All @@ -349,7 +355,7 @@ class Manual extends React.Component {
console.error('Error fetching article:', error);
}

await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for 3 seconds

return this.attemptFetch(tries - 1, code);
};
Expand Down Expand Up @@ -491,6 +497,9 @@ class Manual extends React.Component {
}

let list = { ...this.state.list };
let originalList = { ...this.state.list };
let originalArticles = { ...this.state.articles };

if (source.droppableId === destination.droppableId) {
let items = reorder(
this.getList(source.droppableId),
Expand Down Expand Up @@ -545,6 +554,13 @@ class Manual extends React.Component {

list.loading = false;
this.setState({ list });
}).catch((err) => {
this.setState({
list: originalList,
articles: originalArticles,
});

list.loading = false;
});
}
};
Expand Down

0 comments on commit 1df1d46

Please sign in to comment.