Refactor showModal to avoid having catch everywhere
See original GitHub issue(follow up to this conversation)
Coudln’t we handle this in showModal instead of having to add this everywhere?
Sadly, no After
.catch()
handler promise will go to next.then()
handler, so if we catch that promises inside of dialog wrapper - the caller’s.catch()
will not be called. It actually is not a problem, but browser will show unhandled rejection errors in console. We can either:
- don’t catch that promises and ignore errors in console;
- always add empty catch handler like I did here;
- replace browser’s Promise with something else that does not trigger unhandled rejection errors (e.g. “bluebird”) - prior to this PR we used Angular’s
$q
for this purpose;- change a way we handle dialog’s close/dismiss events (for me current flow looks fine, but that annoying unhandled rejections…)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - Advice on how to refactor a nested try/catch block inside a ...
The best way to avoid nesting is to make it in another function catch (Exception ex) { log.Error("blah blah", ex); FUNCTION_NAME() } private ......
Read more >Weekly Digest (20 January, 2020 - 27 January, 2020) · Issue #4591 ...
#4566 Refactor showModal to avoid having catch everywhere, by arikfr #4565 Change visualizations import to be static, by arikfr ...
Read more >How to re-write the code sample without try/catch block
Try-catch is best used in parts of your code when you think mistakes will occur that are out of your control for whatever...
Read more >window.showModalDialog: What It is and Why You Should ...
When modal.html loads it will assign a value of 'foo' to window.returnValue and close itself via window.close() . The opening window (page.html) ...
Read more >How to avoid try/catch statements nesting/chaining in ...
You are writing try/catch blocks everywhere to prevent errors that crash your app. Sometimes overly because: You want to standardize your errors management....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think the last suggestion is a good one. There just shouldn’t be an error when there isn’t one 😃
We could avoid using promises here and just pass a callback for dialog closed and another (optional) for dialog cancelled. This way handler stays the same and we don’t have to abuse a promise.