From bd74b82c6f60da3cd4e5eba04bedebed59753a3f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 12 Feb 2020 16:58:31 +1100 Subject: [PATCH] feat: don't double parse the incoming JSON body when checking if it is invalid. For @uglyog --- lib/pact_broker/api/resources/base_resource.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/api/resources/base_resource.rb b/lib/pact_broker/api/resources/base_resource.rb index c6ae09a77..688f79772 100644 --- a/lib/pact_broker/api/resources/base_resource.rb +++ b/lib/pact_broker/api/resources/base_resource.rb @@ -84,7 +84,7 @@ def handle_exception e end def params - @params ||= JSON.parse(request.body.to_s, {symbolize_names: true}.merge(PACT_PARSING_OPTIONS)) + @params ||= JSON.parse(request.body.to_s, { symbolize_names: true }.merge(PACT_PARSING_OPTIONS)) #Not load! Otherwise it will try to load Ruby classes. end def params_with_string_keys @@ -123,7 +123,7 @@ def pacticipant_name def invalid_json? begin - JSON.parse(request_body, PACT_PARSING_OPTIONS) #Not load! Otherwise it will try to load Ruby classes. + params false rescue StandardError => e logger.info "Error parsing JSON #{e} - #{request_body}"