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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog for DS API rubygem

## 1.5.3 - 2025-04

- (Jon) Improved API request logging with query string information, which can
assist in debugging and monitoring.
- (Jon) Reordered rescue statements to ensure error handling priority;
connection failures are now handled after service exceptions.
- (Jon) Resolved a bug that caused an error when the API returns a nil item list
by providing a default value of 0.

## 1.5.2 - 2025-03

- (Jon) Updated API logging and response handling
Expand Down
12 changes: 6 additions & 6 deletions lib/data_services_api/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def api_post_json(api, json)

# Get parsed JSON from the given URL
def get_json(http_url, params, options) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# create a well formatted query string from the params hash to be used in the logging
query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')

# parse out the origin from the URL, this is the host but including protocol and port
origin = http_url.split(URI.parse(http_url).path).first

# initiate the message to be logged
logged_fields = {
message: generate_service_message({
msg: "Calling API: #{origin}",
Expand All @@ -67,7 +67,7 @@ def get_json(http_url, params, options) # rubocop:disable Metrics/MethodLength,
# now parse the response
response_body = parse_json(response.body)
# log the number of rows returned
returned_rows = response_body['items'].length
returned_rows = response_body['items'] ? response_body['items'].size : 0
# log the response and status code
logged_fields[:message] = generate_service_message(
{
Expand Down Expand Up @@ -101,12 +101,12 @@ def get_from_api(http_url, accept_headers, params, options) # rubocop:disable Me
instrument_response(response, start_time, 'received')

ok?(response, http_url) && response
rescue Faraday::ConnectionFailed => e
instrument_connection_failure(http_url, e, start_time)
raise e
rescue ServiceException => e
instrument_service_exception(http_url, e, start_time)
raise e
rescue Faraday::ConnectionFailed => e
instrument_connection_failure(http_url, e, start_time)
raise e
end

# Parse the given JSON string into a data structure. Throws an exception if
Expand Down
2 changes: 1 addition & 1 deletion lib/data_services_api/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module DataServicesApi
MAJOR = 1
MINOR = 5
PATCH = 2
PATCH = 3
SUFFIX = nil
VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}#{SUFFIX && ".#{SUFFIX}"}"
end