From dd9393028389ebc8ff6fb917c5dd07feca486c34 Mon Sep 17 00:00:00 2001 From: Alex Willemsma Date: Thu, 15 Jun 2017 11:48:27 -0400 Subject: [PATCH] Don't raise a TypeError when trying to parse nil as JSON. Fixes an issue where when some API's return a 204 response for an empty page of a collection endpoint ActiveResource blows up with a TypeError because it's unable to parse the 'nil' response body as JSON. --- lib/active_resource/formats/json_format.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_resource/formats/json_format.rb b/lib/active_resource/formats/json_format.rb index 827d1cc23a..b92ecc6ff8 100644 --- a/lib/active_resource/formats/json_format.rb +++ b/lib/active_resource/formats/json_format.rb @@ -18,6 +18,7 @@ def encode(hash, options = nil) end def decode(json) + return nil if json.nil? Formats.remove_root(ActiveSupport::JSON.decode(json)) end end