rafamel / rxdb-utils

RxDB's missing pieces
MIT License
69 stars 5 forks source link

React Native red screen error on replication.connect() #6

Open psolom opened 5 years ago

psolom commented 5 years ago

I tried to use replication plugin, but it fails with React Native when the remote DB is down.

The reason is when React Native app in the development mode it stops with a red error screen when faced at console.error(). It's caused by lines:

https://github.com/rafamel/rxdb-utils/blob/master/src/replication.js#L94 https://github.com/rafamel/rxdb-utils/blob/master/src/replication.js#L102

I would suggest the follow options:

  1. replace console.error() with console.log()
  2. even better: add another BehaviorSubject alongside with alive$ (error$ e.g.) to observe errors optionally and not to clutter up the console.
psolom commented 5 years ago

Created a PR #7 for option 2

Now can observe network errors like this:

let replicationStates = db.replicate(...);

replicationStates.error$.subscribe(error => {
    console.log(error); // react native app
    console.error(error); // other apps
});
rafamel commented 5 years ago

Hi Pavel, thanks for the report. As stated on #2 the current filter based implementation will be removed in the future as soon as PouchDB implements selectors. The error$ subscriber seems like an approach I'm not too comfortable with as it would be too easy to confuse that with a subscriber that aggregates all replication errors (which is not the case). Even if that was implemented, this is a completely different kind of error and also one that make little sense to handle other than with the internal implementation of the plugin -if you wanted to handle it differently, it would make more sense to implement the same thing separately. However, I've done two things:

Could you report back on how this behaves within a React Native dev environment?