olofd / react-native-signalr

Use SignalR with React Native
150 stars 61 forks source link

what is best way for catching server errors without red screen of death #25

Closed osmanov closed 7 years ago

osmanov commented 7 years ago

Awesome module,thank you very much for your work! I have a question-what is the best way for catching server errors without red screen of death?

connection.start().done(()=>{
  connection.error( error => {
      //here i get the error from the server
    /*console.log(error.message)-->`it has exceeded the inactivity timeout of 50000 ms. Stopping the connection.` 
    but I can't handle this error here, because the red screen from simulator shoots immediately-`cannot read property supportsKeepAlive of null`*/
  });
})

Thank you!

epodgaetskiy commented 7 years ago

I have same problem.

brunobraun commented 7 years ago

Same problem. I created a handler for the AppState change so when the app state = "background" I stop the connection.. something like this:

_handleAppStateChange = (nextAppState) => {
     if(nextAppState === 'background') {
      this.connectionSignalR.stop();
    }
  }

and I restarted the connection in the "disconnected" signalr event...

for my needs, it worked, hope it can help you

osmanov commented 7 years ago

Thanks @brunobraun, it helped me.

dengue8830 commented 7 years ago

In my case, stopping it in the background gave me a problem, when I restarted signalr it was stays stuck in connecting state, and only connected when i came back to the app. So i stopped and restarted signalr on 'active' AppState

manjeets12 commented 7 years ago

@brunobraun sample code please, I mean more than that _handleAppStateChange change function.Will be great help Thanks