After some investigation this is an approach I've found...
In my python code:
raise HTTP(409, "Team name already exists.",
exception="team-name-not-unique", name=name, cap=cap)
The 400 codes are for client errors and 409 is a "CONFLICT" (e.g., a
conflict for a resource - in my case for an attempt to name a team the same
as another team; cap is just included to illustrate multiple parameters).
The named parameters (name & cap) are added to the response's headers.
In GWT create an exception class TeamNameNotUniqueException.java based on
Exception with a CONST to take a name & cap and a getName() & getCap()
methods.
In the onResponseReceived() of RequestBuilder you can check
response.getStatusCode() == Response.SC_CONFLICT
String type = response.getHeader("exception");
if (type.equals("team-name-not-unique")) {
asyncCallback.onFailure(new
TeamNameNotUniqueException(response.getHeader("name"),
Integer.parseInt(response.getHeader("cap"))));
Put all this in a try/catch block to handle errors and so we can otherwise
assume the headers are correct.
One can add on additional tests again "type" for using alternative
exceptions.
Downsides:
- this approach does place all such exception classes into one file which
doesn't keep code splitting streamlined. At least the exception classes are
small.
- the file has to be edited each time a new exception class is required by
an app.
On Thursday, 11 April 2013 10:42:00 UTC+1, Carl wrote:
>
> Probably a small # of developers in this situation...
>
> I'm using web2py on the server and GWT on the client.
>
> I'd like to throw an exception in my web2py server code and catch and
> handle in in my client GWT code.
>
> So far, when I catch an exception, GWT only reports a generic "500" status
> code when I throw an exception.
>
> Anyone in my boat and has an approach?
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.