5

How can I access the HTTP response body when a web services call fails and my "fault" event listener is call? I can see the original message but can't find a way to access the response.

Here's how I call the webservice

var connect: HTTPService = new HTTPService;
connect.url = "https://app.XYZ.org/services/code?format=xml";
connect.method = "POST";
connect.contentType = "application/x-www-form-urlencoded";
connect.showBusyCursor = true;
connect.resultFormat = "xml";
connect.addEventListener("result", retrieveResults);
connect.addEventListener("fault", retrieveResults);
var params:Object = new Object;
params.username = user;
params.password = password;
params.code = "123";
connect.request = params;
connect.send();

and my event handler function

private function retrieveResults(event:Event): void
{
  var success:Boolean = event.type == ResultEvent.RESULT;
..
}

message

Dwight Kelly
  • 1,232
  • 2
  • 11
  • 17

1 Answers1

4

I'm almost positive this cannot happen. But depending on the error, you could try adding these two listeners to the loader:

loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, httpIOErrorHandler);

One gives the status, so you can find the error. If the status is proper one, the latter should bring you the result (loader.data). There was some occasion that AIR can give you the response but Flash couldn't. You should try both.

Anyways I think it's best to handle the error internal and return ok (status 200) with an error message inside it. Flash is pretty crappy with http statuses :)

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
  • Thank you for the suggestion. I'll give it a try and report back. I'm not able to change the webservice implementation unfortunately. – Dwight Kelly May 16 '14 at 16:45
  • I'm using URLLoader on Adobe AIR for Android and after an HTTP 400 response with a body I was able to get the response body in the IO_ERROR handler. – AlphaCactus Jan 16 '17 at 19:22