Accessing Http status code while using HttpRequest

16 views
Skip to first unread message

krishna

unread,
May 25, 2006, 1:20:51 AM5/25/06
to Google Web Toolkit
Hi All,

I'm new user of GWT. I'm trying to use HTTPRequest.asyncGet. My
question is how do I access Http status codes? I need it to handle
errors. The methods in HTTPRequest doesn't through any exceptions. The
interface ResponseHandler only provides the text response. Can I use
UncaughtExceptionHandler to get this?

My code looks as below..

HTTPRequest.asyncGet(URL, new ResponseTextHandler() {
public void onCompletion(String inResponseText) {
//How to get http status code
}
});


Please help.

Regards,
Krishna

chris

unread,
May 26, 2006, 5:16:40 PM5/26/06
to Google Web Toolkit
Not sure if this is exactly what you want, but the examples provided do
something like this:

if (!HTTPRequest.asyncGet(URL, new ResponseTextHandler() {
public void onCompletion(String inResponseText) {

}}) {

// handle error here
}

The docs say that HTTPRequest.asyncGet() returns false "if the
invocation fails to issue".

krishna

unread,
May 30, 2006, 12:56:56 AM5/30/06
to Google Web Toolkit
Hi chris,

This is not what I want. Say the "URL is not found", the asyncGet would
still return true, and inResponseText would contain the html error page
from the web server..

Thanks,
Krishna

krishna

unread,
May 31, 2006, 12:51:25 AM5/31/06
to Google Web Toolkit
Hi,

It looks like currently it is not possible to access the http status
code while invoking HTTPRequest.asyncGet. The methods in HTTPRequest
doesn't throw any exceptions. The interface ResponseHandler only
provides the text response.


HTTPRequest.asyncGet(URL, new ResponseTextHandler() {
public void onCompletion(String inResponseText) {

//Only way to check for error is by parsing the html.
}

});

It would be better if the onCompletion method in ResponseTextHandler
interface also provided the http status code.

Regards,
Krishna

Miguel Méndez

unread,
May 31, 2006, 11:23:02 AM5/31/06
to Google-We...@googlegroups.com
Hello Krishna,

I could see how this could be useful for situations where you want to get additional information about the server's response.  We appreciate your feedback.

Thanks,
--
Miguel Mendez
GWT Engineer

Miguel Méndez

unread,
Jan 29, 2008, 7:51:19 AM1/29/08
to Eric F, Google Web Toolkit
[Google-We...@googlegroups.com]

You should look at the documentation for RequestBuilder.  Its functionality supercedes the HTTPRequest methods.

On Jan 28, 2008 7:29 PM, Eric F <ericf...@gmail.com> wrote:
I agree with the original poster. I know the JavaScript calls this
translates to allows for dealing with HTTP errors. However not being
able to from the GWT side is frustrating. I need my app to go back to
the login screen when the authentication token expires and my AJAX
requests start returning "FORBIDDEN" HTTP response.. There are just no
ways to detect errors without the HTTP error code. Regex the
responseText for "error" what if someone is searching my application
for "error" and that text is in the responseText of a properly served
request?

Thanks,

-Eric


On May 31 2006, 7:23 am, "Miguel Méndez" <mmen...@google.com> wrote:
> Hello Krishna,
>
> I could see how this could be useful for situations where you want to get
> additional information about the server's response.  We appreciate your
> feedback.
>
> Thanks,
>
> On 5/30/06, krishna <krishnakum...@gmail.com> wrote:
>
>
>
> > Hi chris,
>
> > This is not what I want. Say the "URL is not found", the asyncGet would
> > still return true, and inResponseText would contain the html error page
> > from the web server..
>
> > Thanks,
> > Krishna
>
> --
> Miguel Mendez
> GWT Engineer



--
Miguel
Reply all
Reply to author
Forward
0 new messages