Getting Error message after Invoking Web service in case of a HTTP 400 response code
Just written a web service (WEB-API) that returns a 400 error message on bad request.
Together with the response, the server sends an error message like this:
<?xml version="1.0"?> <Error> <Message>The request is invalid.</Message> <ModelState> <serviceRequest.Id>The Id field is required.</serviceRequest.Id> </ModelState> </Error>
And I use the flash flex for the UI and use the following event handlers to receive the response.
httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=400 responseURL=null] status: 400 [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=400 responseURL=null]
This retrieves the status code = 400 but how to receive the accompanying xml from the web service ?
Any pointers are welcome.
Best practice is to always return status OK (200). Flash is a bit dumb on this and mixing headers with content always makes troubles. Nevertheless if you've embedded it to HTML it also depends on the browser.
So best here would be to return a simple OK status with your error inside, and to just check the data on your Event.COMPLETE handler. If you have error, then it's an error. Just skip the status thing - it will save you time, efforts and sleepless nights :)