rikulo / stomp

STOMP Dart Client for communicating with STOMP-compliant messaging servers.
http://rikulo.org
Other
30 stars 24 forks source link

Ascertain response on connection error #10

Closed revelfire closed 10 years ago

revelfire commented 10 years ago

Part of my last pull request that was not absorbed gave access to the headers from the 'first frame'. The issue that remains is how to handle problems before we get that far. In the case of 302 from the /info request due to 'not logged in' there is presently no way to know the result of that initial upgrade request. It would be very helpful in the event of a connection error, to have the connection error handling callback send back the http response code and/or text.

This was my starting point

static Future<_WSStompConnector> start(String url, 
                                         {void onConnectionError(event)}) {
    WebSocket ws = new WebSocket(url);
    ws.onError.listen(onConnectionError);
    return new _WSStompConnector(ws)._starting.future;
  }

which only gives knowledge of the connection error but not of status code so it is an incomplete solution. If you have suggestions I can try an implementation and offer a pull request.

tomyeh commented 10 years ago

Not sure how to handle it either. However, I modified the code to make it easy to handle (at the application level).

  1. The onFault argument is added to handle exceptions (while onError is only for handling the ERROR fames). Thus, the error event received in WebSocket will be passed to onFault().
  2. connectWith() is added to accept WebSocket, which you can add extra handling before passing to the Stomp client.