Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor showModal to avoid having catch everywhere #4566

Closed
arikfr opened this issue Jan 20, 2020 · 5 comments · Fixed by #4594
Closed

Refactor showModal to avoid having catch everywhere #4566

arikfr opened this issue Jan 20, 2020 · 5 comments · Fixed by #4594

Comments

@arikfr
Copy link
Member

arikfr commented Jan 20, 2020

(follow up to this conversation)

EditTagsDialog.showModal({ tags, getAvailableTags })
.result.then(this.props.onEdit)
.catch(() => {}); // ignore dismiss
};

@arikfr:

Coudln't we handle this in showModal instead of having to add this everywhere?

@kravets-levko

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:

  1. don't catch that promises and ignore errors in console;
  2. always add empty catch handler like I did here;
  3. 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;
  4. change a way we handle dialog's close/dismiss events (for me current flow looks fine, but that annoying unhandled rejections...)
@arikfr arikfr added this to the v9 milestone Jan 20, 2020
@arikfr
Copy link
Member Author

arikfr commented Jan 20, 2020

@kravets-levko here's another suggestion:

When the dialog is closed or dismissed always call resolve the promise, but resolve it with values that represent whether it was dismissed and what the result was.

Is this possible?

@kravets-levko
Copy link
Collaborator

Yes, sure - it's actually option 4 from my list. Also I posted one more comment in that thread:

I'll explore if we can suppress that error with handling unhandledrejection event if error comes from dialog wrapper

@arikfr
Copy link
Member Author

arikfr commented Jan 20, 2020

I don't think the last suggestion is a good one. There just shouldn't be an error when there isn't one :)

@kravets-levko
Copy link
Collaborator

Rejected promise is not an error, actually. I like current flow because it clearly describes two paths - when used accepted some action (then dialog is "resolved"), and when cancelled (then dialog is "rejected"). So when you need to handle only success path - you don't have to add any ifs to your code.

@arikfr
Copy link
Member Author

arikfr commented Jan 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants