From 76041b4868ec0e8d2f9a490d029fc0ca285ca26a Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Thu, 12 Nov 2020 17:56:04 +0800 Subject: [PATCH] remote_settings: log HTML responses as errors --- CHANGELOG.md | 3 +++ lib/airbrake-ruby/remote_settings.rb | 2 +- spec/remote_settings_spec.rb | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dc06b41..4e4063ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Airbrake Ruby Changelog ### master +* Remote config: improved handling of responses that return HTML (they will be + logged correctly) ([#627](https://github.com/airbrake/airbrake-ruby/pull/627)) + ### [v5.1.0][v5.1.0] (October 20, 2020) * Deleted support for dumping/loading the remote config diff --git a/lib/airbrake-ruby/remote_settings.rb b/lib/airbrake-ruby/remote_settings.rb index 1d15d71a..553bab98 100644 --- a/lib/airbrake-ruby/remote_settings.rb +++ b/lib/airbrake-ruby/remote_settings.rb @@ -79,7 +79,7 @@ def fetch_config # AWS S3 API returns XML when request is not valid. In this case we just # print the returned body and exit the method. - if response.start_with?('') logger.error(response) return {} end diff --git a/spec/remote_settings_spec.rb b/spec/remote_settings_spec.rb index 314da1c4..76236323 100644 --- a/spec/remote_settings_spec.rb +++ b/spec/remote_settings_spec.rb @@ -136,6 +136,25 @@ end end + context "when API returns an HTML response" do + let!(:stub) do + stub_request(:get, Regexp.new(endpoint)) + .to_return(status: 200, body: '...') + end + + it "doesn't update settings data" do + settings = nil + remote_settings = described_class.poll(project_id, host) do |data| + settings = data + end + sleep(0.1) + remote_settings.stop_polling + + expect(stub).to have_been_requested.once + expect(settings.interval).to eq(600) + end + end + context "when a config route is specified in the returned data" do let(:new_config_route) do '213/config/111/config.json'