Skip to content

Instantly share code, notes, and snippets.

@florianschmidt1994
Last active August 15, 2016 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianschmidt1994/7c0bd172ae765c1c0426cf8e59902c06 to your computer and use it in GitHub Desktop.
Save florianschmidt1994/7c0bd172ae765c1c0426cf8e59902c06 to your computer and use it in GitHub Desktop.
REGEX: .then(...).catch(...) to try {yield ...} catch (err) { ... }
// Find (Regex):(api\..*)\n(.*\.then.*)\n((.*\n)*?)(.*\}\)\n.*\.catch.*\n)((.*\n)*?)(.*\}\);\n)
// Replace with:try { \n yield $1; \n $3 } catch (err) { \n $6 \n }\n
// Before:
api.rejectSponsoring(teamId, eventId, sponsoringId)
.then(() => {
window.location.reload();
})
.catch((err) => {
console.log(err);
displayError('Ablehnen fehlgeschlagen');
toggleLoading(button);
});
// After:
try {
yield api.rejectSponsoring(teamId, eventId, sponsoringId);
window.location.reload();
} catch (err) {
console.log(err);
displayError('Ablehnen fehlgeschlagen!');
toggleLoading(button);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment