diff --git a/lib/stripe/api_requestor.rb b/lib/stripe/api_requestor.rb index 753c580c1..28ff62d80 100644 --- a/lib/stripe/api_requestor.rb +++ b/lib/stripe/api_requestor.rb @@ -201,6 +201,9 @@ def execute_request(method, path, base_address, ) req_opts = RequestOptions.extract_opts_from_hash(req_opts) + notice = http_resp["stripe-notice"] + warn("WARNING: #{notice}") if notice + resp = interpret_response(http_resp) # If being called from `APIRequestor#request`, put the last response in diff --git a/test/stripe/api_requestor_test.rb b/test/stripe/api_requestor_test.rb index 3d0620081..d240397ee 100644 --- a/test/stripe/api_requestor_test.rb +++ b/test/stripe/api_requestor_test.rb @@ -1312,6 +1312,29 @@ class RequestorTest < Test::Unit::TestCase end context "#execute_request" do + context "Stripe-Notice header" do + should "emit a warning when the header is present" do + stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges") + .to_return( + body: JSON.generate(object: "charge"), + headers: { "Stripe-Notice" => "This is a notice" } + ) + + requestor = APIRequestor.new("sk_test_123") + requestor.expects(:warn).with("WARNING: This is a notice") + requestor.execute_request(:post, "/v1/charges", :api) + end + + should "not emit a warning when the header is absent" do + stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges") + .to_return(body: JSON.generate(object: "charge")) + + requestor = APIRequestor.new("sk_test_123") + requestor.expects(:warn).never + requestor.execute_request(:post, "/v1/charges", :api) + end + end + should "handle success response with empty body" do stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/charges") .to_return(body: "", status: 200)