Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/stripe/api_requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/stripe/api_requestor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading