You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
I think all Android AA projects which use the network have to handle RestClientException, which can occurs for instance if the device lose its connexion.
For one of my project I wrote a wrapper around the @Rest implementation, to surround all network access with try {...} catch (RestClientException e) {...}. It gave me an idea about a possible new feature on AA.
What if we could declare an RestClientException handler in the @Rest annotation ?
The parameter would be an implementation of an interface with a method like onRestClientExceptionThrowed(RestClientException e). If provided then the generated REST service will surround the code with try {...} catch (RestClientException e) {...} and call the handler in the catch clause.
I also use a wrapper with AOP to handle exception on every rest calls.
This issue is somehow related to #508 but you idea is interesting. We could get rid of our wrappers with this :)
I don't think this will be possible, the return value of the rest method is user defined. In this case it's string, but it could be something like CustomerResponse or whatever other object the service returns. I tried playing around with returning null and it seems to work fine. It just returns null back as the object, so the developer can check that return value for null.
I like the idea that the handler returns the same object than the method, because the method caller has a better understanding of what happens. Moreover it allows to use same error handling code between network and server error.
But to achieve that, we have to impose the user to use an AA interface like RestClientResponse<?> for his RestClient methods. The object would encapsulate the server response and would have methods like hasError() or isSuccess().
But probably I'm going to far and it will complexify too much the usage of @RestClient...
Also I don't think it would be backward compatible, I see where you are going with it though. I think returning null would probably be the best bet now so that it doesn't make the rest client more complex to use and stays backward compatible with previous versions.
Activity
DayS commentedon Jun 9, 2013
I also use a wrapper with AOP to handle exception on every rest calls.
This issue is somehow related to #508 but you idea is interesting. We could get rid of our wrappers with this :)
The annotated code could looks like this :
The RestErrorHandler interface :
DayS commentedon Jun 9, 2013
It could also be handled by #339
rockytriton commentedon Jun 10, 2013
I like this idea, what do you think about the last comment I made on #339? We could add this errorHandler() method to that interface as well.
rockytriton commentedon Jul 13, 2013
So, when an exception is thrown, what should be returned from the method call?
I assume the method call goes something like this:
So I guess we would have one of two options, return null (as shown in the example) or rethrow the exception after calling the handler.
DayS commentedon Jul 13, 2013
Maybe the result could be defined by the error handler.
The code could looks like this, so :
And the generated code :
I'm not sure if it's the best solution. Any ideas ?
rockytriton commentedon Jul 13, 2013
I don't think this will be possible, the return value of the rest method is user defined. In this case it's string, but it could be something like CustomerResponse or whatever other object the service returns. I tried playing around with returning null and it seems to work fine. It just returns null back as the object, so the developer can check that return value for null.
tbruyelle commentedon Jul 13, 2013
I like the idea that the handler returns the same object than the method, because the method caller has a better understanding of what happens. Moreover it allows to use same error handling code between network and server error.
But to achieve that, we have to impose the user to use an AA interface like
RestClientResponse<?>for hisRestClientmethods. The object would encapsulate the server response and would have methods likehasError()orisSuccess().But probably I'm going to far and it will complexify too much the usage of
@RestClient...rockytriton commentedon Jul 13, 2013
Also I don't think it would be backward compatible, I see where you are going with it though. I think returning null would probably be the best bet now so that it doesn't make the rest client more complex to use and stays backward compatible with previous versions.
tbruyelle commentedon Jul 14, 2013
Yes you're right.
DayS commentedon Jan 20, 2014
This feature has been implemented in 3.0