Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onError handler for bound methods that call a controller method #5

Open
mglazer opened this issue Aug 22, 2012 · 0 comments
Open

onError handler for bound methods that call a controller method #5

mglazer opened this issue Aug 22, 2012 · 0 comments
Assignees

Comments

@mglazer
Copy link

mglazer commented Aug 22, 2012

I have a controller with the following signature:

public class Controller {

    public void save() throws InvalidObjectException {
        callExternalServiceThatThrowsException();
    }

}

The fact that it throws InvalidObjectException is not important
what is important is that it throws an exception when some error occurs
in the external service, beit a ReST API or what.

This seems totally reasonable, and since the controller should be completely
agnostic of the view, throwing an exception and having it bubble up to
an appropriate error handler seems valuable. At the moment, I have no way
of handling the error.

I want to be able to pass this error up to the view so that it can handle
it in a graceful manner. Such as:

public void handleError( Throwable t ) {
    displayErrorMessage("I got an error!", t);
}

I currently can do this, sort of, by calling an reportError method or
something on the model, but that tends to clog up my model with a lot of
error reporting code (it has to hold onto the error for just long enough
for the view to respond to it).

This is similar to the callback systems from jQuery $.ajax method:

$.ajax({
    success: someCallback
    error: someErrorCallback
});

I could forsee this looking like the following in cinch:

@OnClick( call = "save", onError = "handleError" )
private JButton sendAPICall;

Is there potentially a better way to solve this?

@ghost ghost assigned dcervelli Aug 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants