I was a bit dismayed on Friday to find that Flex is severely crippled in the way it handles fault responses via the HTTPService component. In short, it doesn’t provide the response body if the HTTP status code indicates an error. It doesn’t even tell you the status code so you can create an intelligent error message. This is easy to do in javascript, so its lame to find that Flex and actionscript are actually less capable in this regard. I found another post describing this issue where blame is placed on the browser implementation.
I had planned to to return HTTP 404 plus an xml fragment containing the error message when a resource wasn’t found via a given id number, but now that’s out the window. Instead I’m always returning OK, and switching based on the body XML content. Oh well.
In order to do so, I needed to determine the root node of the xml – was it “error” or something else? Using e4x, navigating the dom is usually child’s play – just nodename.childname.text() for example. This is where I made a “rookie mistake” in not realizing that the XML object actually represents the root node, not some super-root. So I was testing for the existence of x.error (where x is the XML object, and error would be a first level child) rather than just checking the localname of the xml object, which in fact is the node named “error”. Maybe this will show up in google and help someone experiencing a similar brain-fart one day.
This was exactly what I was looking for! And, yes… I found it through Google.
I had started to think down these lines, but couldn’t come up with how to test the name. Thanks!