Merge pull request #1049 from cantino/rescue_json_errors_on_deserialize

Handle truncated payloads

Andrew Cantino %!s(int64=9) %!d(string=hace) años
padre
commit
d15f389da0
Se han modificado 1 ficheros con 3 adiciones y 0 borrados
  1. 3 0
      lib/json_with_indifferent_access.rb

+ 3 - 0
lib/json_with_indifferent_access.rb

@@ -1,6 +1,9 @@
1 1
 class JSONWithIndifferentAccess
2 2
   def self.load(json)
3 3
     ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(json || '{}'))
4
+  rescue JSON::ParserError
5
+    Rails.logger.error "Unparsable JSON in JSONWithIndifferentAccess: #{json}"
6
+    { 'error' => 'unparsable json detected during de-serialization' }
4 7
   end
5 8
 
6 9
   def self.dump(hash)