Skip to content

Commit

Permalink
96338 Better erroring messages when getting copays (#19329)
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldrk authored Nov 14, 2024
1 parent ab28b3e commit f8752bb
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/services/medical_copays/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,32 @@ def initialize
# @return [Faraday::Response]
#
def post(path, params)
with_monitoring do
connection.post(path) do |req|
req.body = Oj.dump(params)
if Flipper.enabled?(:debts_copay_logging) && !Rails.env.development?
with_monitoring_and_error_handling do
connection.post(path) do |req|
req.body = Oj.dump(params)
end
end
else
with_monitoring do
connection.post(path) do |req|
req.body = Oj.dump(params)
end
end
end
end

def with_monitoring_and_error_handling(&)
with_monitoring(2, &)
rescue => e
handle_error(e)
end

def handle_error(error)
Rails.logger.error("MedicalCopays::Request error: #{error.message}")
raise error
end

##
# Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id
#
Expand Down
4 changes: 4 additions & 0 deletions app/services/medical_copays/vbs/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def get_pdf_statement_by_id(statement_id)
end

def get_copay_response
if Flipper.enabled?(:debts_copay_logging)
Rails.logger.info("MedicalCopays::VBS::Service#get_copay_response request data: #{@user.uuid}")
end

request.post("#{settings.base_path}/GetStatementsByEDIPIAndVistaAccountNumber", request_data.to_hash)
end

Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ features:
debts_cache_vbs_copays_empty_response:
actor_type: user
description: Enables caching of empty VBS medical copay response
debts_copay_logging:
actor_type: user
description: Logs copay request data
decision_review_hlr_email:
actor_type: user
description: Send email notification for successful HLR submission
Expand Down
43 changes: 43 additions & 0 deletions spec/services/medical_copays/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,49 @@

subject.post(path, params)
end

context 'with debt_copay_logging Flipper enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:medical_copays_api_key_change).and_return(true)
allow(Flipper).to receive(:enabled?).with(:debts_copay_logging).and_return(true)
allow(Rails.env).to receive(:development?).and_return(false)
end

it 'calls the with_monitoring_and_error_handling method' do
# rubocop:disable RSpec/SubjectStub
expect(subject).to receive(:with_monitoring_and_error_handling)
# rubocop:enable RSpec/SubjectStub
subject.post(path, params)
end

it 'logs the error message' do
allow_any_instance_of(Faraday::Connection)
.to receive(:post).with(path).and_raise(StandardError.new('Something went wrong'))
expect(Rails.logger).to receive(:error).with(
'MedicalCopays::Request error: Something went wrong'
)

expect do
subject.post(path, params)
end.to raise_error(StandardError, 'Something went wrong')
end
end

context 'with debt_copay_logging Flipper not enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:medical_copays_api_key_change).and_return(true)
allow(Flipper).to receive(:enabled?).with(:debts_copay_logging).and_return(false)
allow(Rails.env).to receive(:development?).and_return(false)
end

it 'calls the with_monitoring_and_error_handling method' do
# rubocop:disable RSpec/SubjectStub
expect(subject).to receive(:with_monitoring)
# rubocop:enable RSpec/SubjectStub
allow_any_instance_of(Faraday::Connection).to receive(:post).with(path).and_return(response)
subject.post(path, params)
end
end
end

describe '#get' do
Expand Down
27 changes: 27 additions & 0 deletions spec/services/medical_copays/vbs/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ def stub_get_copays(response)
] })
end
end

context 'with debts_copay_logging flipper enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:debts_copay_logging).and_return(true)
allow(Flipper).to receive(:enabled?).with(:medical_copays_api_key_change).and_return(true)
allow(Flipper).to receive(:enabled?).with(:debts_cache_vbs_copays_empty_response).and_return(true)
allow(Flipper).to receive(:enabled?).with(:debts_cache_vbs_copays_empty_response).and_return(true)
allow(Flipper).to receive(:enabled?).with(:medical_copays_zero_debt).and_return(true)
allow(Flipper).to receive(:enabled?).with(:medical_copays_six_mo_window).and_return(true)
end

it 'logs that a response was cached' do
allow_any_instance_of(MedicalCopays::VBS::RequestData).to receive(:valid?).and_return(true)
allow_any_instance_of(MedicalCopays::VBS::RequestData).to receive(:to_hash).and_return(
{ edipi: '123456789', vistaAccountNumbers: [36_546] }
)
allow_any_instance_of(MedicalCopays::Request).to receive(:post)
.and_return(Faraday::Response.new(status: 200, body: []))

expect(Rails.logger).to receive(:info).with(
a_string_including('MedicalCopays::VBS::Service#get_copay_response request data: ')
)
VCR.use_cassette('user/get_facilities_empty', match_requests_on: %i[method uri]) do
subject.get_copays
end
end
end
end

describe '#get_copay_by_id' do
Expand Down

0 comments on commit f8752bb

Please sign in to comment.