react-firebase icon indicating copy to clipboard operation
react-firebase copied to clipboard

Handle errors?

Open gmaclennan opened this issue 8 years ago • 2 comments

There is currently no way of capturing errors from database reads, for example if permission is denied. We could add a handler to https://github.com/unfold/react-firebase/blob/master/src/connect.js#L106

subscriptionRef.on('value', update, onError)

But how to map that value to props? We could just map the value to the same prop key, which would require an additional check props[key] instanceof Error, or we could extend the mergeProps function to also pass and error argument that the user could map to props as they desire, something like (we could attach the key to the error for convenience):

const mergeProps = (ownProps, firebaseProps, error) => ({
  error: 'There was an error reading ' + error.key + ' Firebase said: ' + error.message
})

gmaclennan avatar Jun 22 '17 17:06 gmaclennan

@gmaclennan I've taken a stab a this in https://github.com/unfold/react-firebase/tree/merge-props-error-handling if you'd like to give it a try. There's no docs yet but the added tests should be understandable enough.

simenbrekken avatar Aug 01 '17 12:08 simenbrekken

Are you still tracking this @gmaclennan or should we go ahead without your input?

simenbrekken avatar Aug 28 '17 07:08 simenbrekken