fix: Fix JSON parser crash if an empty body (such as HTTP 204) is received

This commit is contained in:
Daniel Azuma 2020-10-19 13:30:38 -07:00 committed by GitHub
parent 0d5fb8c094
commit 330d7ef719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -83,6 +83,7 @@ module Google
return super if options && options.skip_deserialization return super if options && options.skip_deserialization
return super if content_type.nil? return super if content_type.nil?
return nil unless content_type.start_with?(JSON_CONTENT_TYPE) return nil unless content_type.start_with?(JSON_CONTENT_TYPE)
body = "{}" if body.empty?
instance = response_class.new instance = response_class.new
response_representation.new(instance).from_json(body, unwrap: response_class) response_representation.new(instance).from_json(body, unwrap: response_class)
instance instance