views:

2852

answers:

3

I get a 2032 stream error from Flash in response to POST requests that return "201 Created" in IE (Firefox works fine). Since Flash doesn't provide access to the HTTP status I can't tell that it has actually succeeded. The request is being made with HTTPService.

Any suggestions? Has anyone else seen this?

Thanks, Alex

+1  A: 

Try using a debug proxy to take a peek at the traffic, I like Charles.

grapefrukt
A: 

Installed Charles, thanks, very cool! It confirmed that the server is returning a success code (201) but Flex sends a FaultEvent.

+3  A: 

I found a way around this on my Flex on Rails application. I was seeing the same problem in IE - my development.log in Rails gave a 201 message, but this caused a fault coming back to Flex. I found a reference in a new book called Flex On Rails by Tony Hillerson and Daniel Wanja, on p. 31. It involves catching the 201 error and changing the header. Here's my ApplicationController file:

 class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  include AuthenticatedSystem
  before_filter :login_required


  after_filter :flex_error_handling
  def flex_error_handling
    response.headers['Status'] = interpret_status(200) if response.headers['Status'] == interpret_status(422)
    response.headers['Status'] = interpret_status(200) if response.headers['Status'] == interpret_status(201)
  end
  def rescue_action_in_public(exception)
    render_exception(exception)


  end
  def rescue_action_locally(exception)
    render_exception(exception)
  end
    rescue_from ActiveRecord::RecordNotFound, :with => :render_exception
  def render_exception(exception)
    render :text => "<errors><error>#{exception}</error></errors>", :status => 200
  end
end

The action of changing the 422 status message to 200 was part of Hillerman/Wanja's original suggestions to change the 2032 Stream Error into something more friendly, so that invalid record errors are sent back to the Flex UI.