FirebaseExtended / polymerfire

Polymer Web Components for Firebase
https://www.webcomponents.org/element/firebase/polymerfire
MIT License
459 stars 142 forks source link

Improve error events firing and handling #340

Open FluorescentHallucinogen opened 6 years ago

FluorescentHallucinogen commented 6 years ago

If I use plain Firebase JavaScript SDK API, I deal with JS promises and can easily handle success and errors:

firebase.database().ref(`/posts/${postId}`).set({
  body: text
}).then(response => {
  // do something
}).catch(error => {
  // handle error
});

But if I use e.g. <firebase-document>, how do I know if the data was successfully written to the database or an error occurred (and which one)?:

<firebase-document
    path="/posts/[[postId]]/body"
    data="{{text}}">
</firebase-document>

Seems, only <firebase-auth> web component can fire error events:

<firebase-auth
    provider="google"
    user="{{user}}"
    on-error="handleError">
</firebase-auth>

But error event is not listed in https://webcomponents.org/element/firebase/polymerfire/elements/firebase-auth#events.

The following JSDoc annotation should be added to <firebase-auth> source code to fix it:

/**
 * Fired when an error occurs.
 *
 * @event error
 * @param {Object} The returned error object.
 */

What about adding error events to other PolymerFire web components? And how to handle success? What about adding success events?

FluorescentHallucinogen commented 6 years ago

@tjmonsi @mbleigh PTAL.

FluorescentHallucinogen commented 6 years ago

@merlinnot PTAL.