lib/itrp/client/response.rb in itrp-client-1.0.1 vs lib/itrp/client/response.rb in itrp-client-1.0.2

- old
+ new

@@ -20,11 +20,16 @@ # The JSON value, if single resource is queried this is a Hash, if multiple resources where queried it is an Array # If the response is not +valid?+ it is a Hash with 'message' and optionally 'errors' def json return @json if defined?(@json) - # no body, no json - data = {message: @response.message.blank? ? 'empty body' : @response.message.strip} if @response.body.blank? + # no content, no JSON + if @response.code.to_s == '204' + data = {} + elsif @response.body.blank? + # no body, no json + data = {message: @response.message.blank? ? 'empty body' : @response.message.strip} + end begin data ||= JSON.parse(@response.body) rescue ::Exception => e data = { message: "Invalid JSON - #{e.message} for:\n#{@response.body}" } end