Hi, how are you doing? :)
I faced a problem with GWT but I decided to discuss it rather than to submit a bug directly:
I'm 'standardizing' the server errors behavior on my app, and I was surprised to see how
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext
is closed code: here is a snippet of how the payload is read:
public void processPayload(final Receiver<Void> receiver, String payload) {
/*some code here... */
// Send return values
Set<Throwable> causes = null;
for (int i = 0, j = state.invocations.size(); i < j; i++) {
try {
if (response.getStatusCodes().get(i)) {
state.invocations.get(i).onSuccess(response.getInvocationResults().get(i));
} else {
ServerFailureMessage failure =
AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ServerFailureMessage.class,
response.getInvocationResults().get(i)).as();
state.invocations.get(i).onFail(
new ServerFailure(failure.getMessage(), failure.getExceptionType(), failure
.getStackTrace(), failure.isFatal()));
}
} catch (Throwable t) {
if (causes == null) {
causes = new HashSet<Throwable>();
}
causes.add(t);
}
}
/* and continues...*/
I was wondering why there is no method to express
state.invocations.get(i).onSuccess
and
state.invocations.get(i).onFail
But why am I concerned?
I wanted to intercept the server failures and use an exception recognition and an I18n mechanism to display errors accordingly (buisness errors along with possible actions, and system errors as a boring alert)
Fortunately I created a BasicReceiver at the very start of the project (2 years ago) and I insisted it is important to have our own Receiver, and only some developers forgot to use it, so I have a centralized way to handle onFailure() calls. But architecturally speaking this is not good to rely on the fact that developers will not forget to use the good class, after all nothing obliges them to use it, it compiles, it works. But only if there is an error, there will be a per case bug.
So I wanted to propose one or both these code changes:
- externalize methods, so that AbstractRequestContext can be extended : state.invocations.get(i).onSuccess(...) -> becomes : AbstractRequestContext#onSuccess( AbstractRequest res )
- add an observer mechanism so we can get warned of transport events
Note: I already have my own implementation of RequestTransport but since exceptions pass in the onTransportSuccess() method, I cannot detect them if I don't parse the payload
Note2: this post is really motivated by empathy (only to make a better GWT platform), It's not specific to my project, so don't take my suggestions as personal attacks :)
thanks for reading