Skip to content

Instantly share code, notes, and snippets.

@cypriss
Created May 11, 2012 21:09
Show Gist options
  • Save cypriss/2662430 to your computer and use it in GitHub Desktop.
Save cypriss/2662430 to your computer and use it in GitHub Desktop.
Don't explode from invalid XML
# This implmements a custom parse strategy of XML. It's exactly the same as Rails (Hash.from_xml)
# except that it rescues syntax errors instead of exploding.
ActionController::Base.param_parsers[Mime::XML] = Proc.new do |body|
if body.blank?
{}.with_indifferent_access
else
begin
Hash.from_xml(body).with_indifferent_access
rescue Nokogiri::XML::SyntaxError => e
Mouth.increment("corner_cases.nokogiri_syntax_error")
{}.with_indifferent_access
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment