2
votes

I am starting to use Firebase Cloud function and it is generally great. The only thing that is not clear to me is how to handle a failure of the process that runs in the trigger function.

For example - I have a trigger on Firebase Auth that creates a Stripe Customer on our Stripe account every time a new user is created. It is possible that the Stipe API call will fail. In a "Normal" HTTP request I will return an error to the client that will respond accordingly, but on a cloud function I do not have a callback from the trigger (Or do I?)

Any Idea how to handle this while using cloud function?

Thanks

1

1 Answers

1
votes

What you do in an auth trigger depends on the APIs you're calling. As you know, in HTTP functions, you return a response to the client for every code path that can occur. For all other types of functions (including Auth functions), you need to return a promise that becomes resolved when all the work is complete. If the Stripe API uses promises, you can simply use those (in addition to any others in your code) to return a single promise. If you have a promise in hand, you can know if its work fails by using catch() on that promise to trap the error.

I strongly recommend reading the Firebase docs on promises, and also looking at sample code (especially the Stripe example).