Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added mvi service handling for 200 from vaafi but 500 from mvi #454

Merged
merged 3 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions lib/mvi/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def call(operation, body)
Rails.logger.error response.body
raise MVI::HTTPError.new('MVI HTTP call failed', response.status)
end
raise MVI::HTTPError.new('MVI internal server error', 500) if body_has_error(response.body)
response
end

Expand All @@ -79,6 +80,17 @@ def request_failure_handler(operation, xml)
Rails.logger.error "mvi #{operation} request failure: #{xml}"
raise MVI::RequestFailureError
end

def body_has_error(body)
doc = Ox.parse(body)
fault_element = doc.locate('env:Envelope/env:Body/env:Fault').first
return false unless fault_element
fault_code = fault_element.locate('faultcode').first
fault_string = fault_element.locate('faultstring').first
Rails.logger.error "MVI fault code: #{fault_code.nodes.first}" if fault_code
Rails.logger.error "MVI fault string: #{fault_string.nodes.first}" if fault_string
true
end
end
class ServiceError < StandardError
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/mvi/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@
end
end
end

context 'when MVI returns 500 but VAAFI sends 200' do
it 'raises an MVI::HTTPError' do
VCR.use_cassette('mvi/find_candidate/internal_server_error') do
expect(Rails.logger).to receive(:error).with('MVI fault code: env:Server').once
expect(Rails.logger).to receive(:error).with('MVI fault string: Internal Error (from server)').once
expect { subject.find_candidate(message) }.to raise_error(MVI::HTTPError, 'MVI internal server error')
end
end
end
end

describe MVI::RecordNotFound do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.