Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

CANCEL is not caught from Promise #13

Open
tomoguisuru opened this issue Jun 29, 2017 · 2 comments
Open

CANCEL is not caught from Promise #13

tomoguisuru opened this issue Jun 29, 2017 · 2 comments

Comments

@tomoguisuru
Copy link

I'm probably doing something wrong but I can't seem to get a failed promise to cancel the pipeline.

pipeline__submitForm: computed(function() {
  return pipeline(this, [
    step('pipe__showLoader'),
    step('pipe__getToken'),
    step('pipe__processCharge'),
    step('pipe__showReceipt'),
  ]).onCancel(_c => this.handleCancellation(_c));
}),

pipe__getToken() {
  return stripe.createToken(card).then(response => return response.id, reason => CANCEL(reason.error.message));
}

Example using the demo Twiddle:
https://ember-twiddle.com/2709c2faca0c7038ee639558aabad865?openFiles=controllers.application.js%2C

@poteto
Copy link
Owner

poteto commented Jun 30, 2017

I hope you aren't using this addon in production, it's still very experimental.

To solve your issue, for now you need to return the cancellation token outside of the promise. I have not implemented the case where the cancellation token is returned inside of a promise. Perhaps have another step called pipe__validateToken which does that:

pipe__getToken() {
  return stripe.createToken(card).then(response => response, reason => reason);
},

pipe__validateToken(response) {
  if (response.error) {
    return CANCEL(response.error.message);
  }
  return response.id;
}

@tomoguisuru
Copy link
Author

nope, not using it in prod, just trying it out. Thanks for the feedback

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

No branches or pull requests

2 participants