I have and Google Web Toolkit (Multipart) Form which post a file to my servlet. When error condition is happening in servlet I return an error. When everything is OK I return an JSON string.
...
response.setContentType("text/html");
response.setCharacterEncoding("UTF8");
response.getWriter().write(out.toString());
} catch (FileUploadException e) {
response.sendError(500, e.getMessage());
} catch (Exception e) {
response.sendError(500, e.getMessage());
}
The problem is that I cant find a way to handle this in client side. This is the event that is fired when post goes OK and when error code is returned. But I can't find how to find is it OK or NOT? And how can I get an error message from Exception in client code?
@UiHandler("form")
void submitComplete(SubmitCompleteEvent event)
{
...
I have and Google Web Toolkit (Multipart) Form which post a file to my servlet. When error condition is happening in servlet I return an error. When everything is OK I return an JSON string.
...
response.setContentType("text/html");
response.setCharacterEncoding("UTF8");
response.getWriter().write(out.toString());
} catch (FileUploadException e) {
response.sendError(500, e.getMessage());
} catch (Exception e) {
response.sendError(500, e.getMessage());
}
The problem is that I cant find a way to handle this in client side. This is the event that is fired when post goes OK and when error code is returned. But I can't find how to find is it OK or NOT? And how can I get an error message from Exception in client code?
@UiHandler("form")
void submitComplete(SubmitCompleteEvent event)
{
...
Share Improve this question edited Aug 5, 2019 at 19:09 Glorfindel 22.7k13 gold badges89 silver badges118 bronze badges asked Aug 11, 2010 at 7:50 Julian PopovJulian Popov 17.5k12 gold badges57 silver badges86 bronze badges 5
- You could override the default error documents (in your server's configuration) so that they just output, for example, the status code - it would be easier to search for "500" in the response, then parse the whole default error page. – Igor Klimer Commented Aug 11, 2010 at 8:43
- @Igor Klimer: Is it worth to change the server configuration for just one servlet? Why I can't find response code (200 or 500)? – Julian Popov Commented Aug 11, 2010 at 9:04
-
Well, it is weird that you don't have access to the response code, like in
RequestBuilder
... But it seems nothing can be done for now (maybe create a new issue/improvement on GWT's bug tracker?) Two related threads from GWT's group: groups.google./group/google-web-toolkit/browse_thread/thread/… and groups.google./group/google-web-toolkit/browse_thread/thread/…. It seems it's important to set content-type of your response totext/html
to ensure it works on all browsers (even if it actually contains JSON). – Igor Klimer Commented Aug 11, 2010 at 9:23 - @Igor Klimer Thank you very much :) It seems that I have to return error messages with code 200 or change server configuration (or ignore everything returned from servlet that is not correct JSON) – Julian Popov Commented Aug 11, 2010 at 9:37
- Glad I could help :) I've added an answer summarizing the above ments, so that someone else could easier find the answer to this question. – Igor Klimer Commented Aug 11, 2010 at 12:38
1 Answer
Reset to default 7Currently, there doesn't seem to be a suitable method available (like Response
's getStatusCode
). You have to do with the error documents your server returns to you in SubmitCompleteEvent.getResults()
. You can make this task easier by setting custom error documents on your server (which you should either way for your production server) that are easier to parse/handle.
Related threads on GWT's Google Group: one and two.