Skip to content

Instantly share code, notes, and snippets.

@kares
Created September 6, 2009 09:41
Show Gist options
  • Save kares/181736 to your computer and use it in GitHub Desktop.
Save kares/181736 to your computer and use it in GitHub Desktop.
action pack request exception patching for the pre 2.3 era
# Patch request to receive exceptions from body parsing (e.g. XML parsing)
ActionController::AbstractRequest.class_eval do
alias_method :parse_formatted_request_parameters_unsafely, :parse_formatted_request_parameters
def parse_formatted_request_parameters
begin
parse_formatted_request_parameters_unsafely #super
rescue Exception => e # YAML, XML or Ruby code block errors
self.env['EXCEPTION'] = e # there will be a before filter to check for this and re-raise
{ #"body" => raw_post,
"content_type" => content_type_with_parameters, "content_length" => content_length }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment