gwt-channel-api icon indicating copy to clipboard operation
gwt-channel-api copied to clipboard

Channel class swallows errors for failed RPC to ChannelService.join()

Open vidalborromeo opened this issue 9 years ago • 3 comments

Hi there, thanks for the great library. In the Channel.join() method I noticed that the onError() callback for the RPC is empty, i.e. it will hide errors on failed calls to the server:

    public void join() {
        channelService.join(channelName, new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable throwable) {
                // Exceptions disappear here
            }

            @Override
            public void onSuccess(String t) {
                token = t;
                join(token);
            }
        });
    }

This is probably a rare event, but potentially tricky to debug when it happens. I can think of a few potential solutions. Here's the first two:

  1. Add onJoinError() to ChannelListener:
public interface ChannelListener extends RemoteService {

    void onJoinError(Throwable caught);

    void onMessage(String message);

    void onOpen();

    void onError(int code, String description);

    void onClose();
}
  1. Add something like FailedJoinCallback and join(FailedJoinCallback callback) to Channel:
public interface FailedJoinCallback {
    void onFailedJoin(Throwable caught);
}

    public void join(FailedJoinCallback callback) {
        channelService.join(channelName, new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
                callback.onFailedJoin(caught);
            }

            @Override
            public void onSuccess(String t) {
                token = t;
                join(token);
            }
        });

vidalborromeo avatar Aug 29 '16 17:08 vidalborromeo

Hi

I guess this problem applies to send as well, and one might want to get a callback on onSuccess.
Would it be odd to accept new AsyncCallback<String> as an argument to both join and send? (Or as optional argument, additional method). I'm not sure about the whole token stuff, but for onSuccess the success could be delegated.

eirikb avatar Aug 29 '16 19:08 eirikb

I think that could work, especially as an optional argument in an additional method. A usage example for new users would help avoid confusion between the two versions. For the callback passed to join(AsyncCallback<String>) you might also want to explain in a comment/javadoc the String they're receiving in onSuccess(String).

AsyncCallback<Void> is yet another option, but maybe not as widely useful as AsyncCallback<String>.

vidalborromeo avatar Aug 30 '16 01:08 vidalborromeo

Using AsyncCallback<Void> could be a good idea, as end users might not need to know about the token. Then again there's no reason not to give it out.

eirikb avatar Aug 30 '16 04:08 eirikb