Skip to content

Instantly share code, notes, and snippets.

@Pacane
Last active February 17, 2016 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pacane/30462f0514c80206b7ff to your computer and use it in GitHub Desktop.
Save Pacane/30462f0514c80206b7ff to your computer and use it in GitHub Desktop.
// ...
requestStaticInjection(RestCallbackImpl.class);
bind(ConnectionErrorNotifier.class).to(ConnectionErrorConsoleNotifier.class).asEagerSingleton();
// ...
public class ConnectionErrorConsoleNotifier implements ConnectionErrorNotifier{
@Override
public void onConnectionError(ConnectionErrorEvent event) {
GWT.log("An error occured while communicating with the server");
}
@Inject
public ConnectionErrorConsoleNotifier(EventBus eventBus) {
eventBus.addHandler(ConnectionErrorEvent.TYPE, this);
}
}
public interface ConnectionErrorNotifier extends ConnectionErrorEventHandler {
}
public abstract class RestCallbackImpl<T> implements RestCallback<T>, HasHandlers {
@Inject
static EventBus eventBus;
private Response response;
@Override
public void setResponse(Response response) {
this.response = response;
}
@Override
public void onFailure(Throwable throwable) {
onError(response);
}
public void onError(Response response) {
ConnectionErrorEvent.fire(this);
}
@Override
public void fireEvent(GwtEvent<?> gwtEvent) {
eventBus.fireEventFromSource(gwtEvent, this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment