Created
May 11, 2012 21:09
-
-
Save cypriss/2662430 to your computer and use it in GitHub Desktop.
Don't explode from invalid XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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