Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: How to return (and handle) an error from multipart form (file) upload

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)
{
    ...

Debug

like image 788
Julian Popov Avatar asked Aug 11 '10 07:08

Julian Popov


1 Answers

Currently, 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.

like image 188
Igor Klimer Avatar answered Sep 21 '22 13:09

Igor Klimer