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

lg-14790 handle network failures for socure #11430

Merged
merged 18 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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 app/services/doc_auth/socure/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Request
def fetch
# return DocAuth::Response with DocAuth::Error if workflow is invalid
http_response = send_http_request
if http_response.nil? || !http_response.body.present?
return handle_invalid_response(http_response)
end
return handle_invalid_response(http_response) unless http_response.success?

handle_http_response(http_response)
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 5 additions & 0 deletions app/services/doc_auth/socure/requests/document_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def handle_http_response(http_response)
end

def handle_invalid_response(http_response)
if http_response.nil? || !http_response.body.present?
message = [self.class.name, 'Unexpected HTTP response', 500].join(' ')
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved
exception = DocAuth::RequestError.new(message, http_response.status)
return handle_connection_error(exception: exception)
end
message = [
self.class.name,
'Unexpected HTTP response',
Expand Down
25 changes: 25 additions & 0 deletions app/services/doc_auth/socure/requests/docv_result_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ def handle_http_response(http_response)
)
end

def handle_invalid_response(http_response)
if http_response.nil? || !http_response.body.present?
message = [self.class.name, 'Unexpected HTTP response', 500].join(' ')
exception = DocAuth::RequestError.new(message, http_response.status)
return handle_connection_error(exception: exception)
end
message = [
self.class.name,
'Unexpected HTTP response',
http_response.status,
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved
].join(' ')
exception = DocAuth::RequestError.new(message, http_response.status)
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved

response_body = begin
http_response.body.present? ? JSON.parse(http_response.body) : {}
rescue JSON::JSONError
{}
end
handle_connection_error(
exception: exception,
status: response_body.dig('status'),
status_message: response_body.dig('msg'),
)
end

def handle_connection_error(exception:)
NewRelic::Agent.notice_error(exception)
DocAuth::Socure::Responses::DocvResultResponse.new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ def get_data(path)
end

def parsed_response_body
@parsed_response_body ||= JSON.parse(http_response.body).with_indifferent_access
@parsed_response_body ||= begin
http_response.body.present? ? JSON.parse(
http_response.body,
).with_indifferent_access : {}
rescue JSON::JSONError
{}
end
end

def state_id_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@
get(:show)
expect(response).not_to be_nil
end
it 'socure nil response still gives a result to user' do
stub_request(:post, fake_socure_endpoint).to_return(
status: 500,
body: nil,
)
get(:show)
expect(response).not_to be_nil
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@
get(:show)
expect(response).not_to be_nil
end
it 'socure nil response still gives a result to user' do
stub_request(:post, fake_socure_endpoint).to_return(
status: 500,
body: nil,
)
get(:show)
expect(response).not_to be_nil
end
end
end

Expand Down