From ee32033641661dcdfe0f58d6edd993823daf259d Mon Sep 17 00:00:00 2001 From: John Bachir Date: Fri, 13 Nov 2026 22:49:35 -0500 Subject: [PATCH] Add raw_body to HTTPService::Response The client parsed the response body into a model and discarded it, so there was no public way to store or log a response as received, or to read a field the models don't cover yet. raw_body is the body string before parsing. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 3 +++ lib/minfraud/http_service/response.rb | 10 +++++++++- spec/http_spec.rb | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3183fc3..48acffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## v2.11.0 +* Added `raw_body` to `Minfraud::HTTPService::Response`. It is the response + body as the web service sent it, before parsing. Use it to store or log + the full response, including any fields this library does not model yet. * Added the `phone_verification_method`, `phone_was_verification_successful`, and `phone_verification_time` attributes to `Minfraud::Components::Billing` and diff --git a/lib/minfraud/http_service/response.rb b/lib/minfraud/http_service/response.rb index fa5e71a..0261e2f 100644 --- a/lib/minfraud/http_service/response.rb +++ b/lib/minfraud/http_service/response.rb @@ -23,6 +23,13 @@ class Response # Minfraud::Model::Factors, Minfraud::Model::Error, nil] attr_reader :body + # The response body as the web service sent it, before parsing. Use it + # to store or log the full response, including any fields this library + # does not model yet. + # + # @return [String] + attr_reader :raw_body + # @param endpoint [Symbol, nil] endpoint name, like :score. # # @param locales [Array, nil] locales, like ["en"]. @@ -33,7 +40,8 @@ class Response # # @raise [JSON::ParserError] if there was invalid JSON in the response. def initialize(endpoint, locales, response, body) - @status = response.code + @status = response.code + @raw_body = body @body = make_body( endpoint, diff --git a/spec/http_spec.rb b/spec/http_spec.rb index a15381a..a4d551e 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -32,9 +32,10 @@ }, ) - score_model = assessment.score.body + response = assessment.score - expect(score_model.risk_score).to eq 42.1 + expect(response.body.risk_score).to eq 42.1 + expect(response.raw_body).to eq '{"risk_score":42.1}' end it 'makes an HTTP request resulting in an HTTP 401' do