From 6015205728d86c3e14309c635d03fdeb8e84aeab Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Tue, 1 Apr 2025 14:37:54 +0100 Subject: [PATCH 1/4] Fix: Handles nil item lists in responses - Fixes a bug that causes an error when the API returns a response with a nil item list by providing a default value of 0. --- lib/data_services_api/service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data_services_api/service.rb b/lib/data_services_api/service.rb index b5cef91..f7f90be 100644 --- a/lib/data_services_api/service.rb +++ b/lib/data_services_api/service.rb @@ -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( { From 1dea82bc18307018a9b2f48b909a1d99e7c4bb33 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Tue, 1 Apr 2025 14:39:06 +0100 Subject: [PATCH 2/4] Refactor: Improves API request logging and error handling - Improves the logging of API requests by creating a formatted query string for logging purposes. - Improves error handling by reordering the rescue block for `Faraday::ConnectionFailed` to ensure proper instrumentation of connection failures before raising the exception. --- lib/data_services_api/service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/data_services_api/service.rb b/lib/data_services_api/service.rb index f7f90be..bde2d24 100644 --- a/lib/data_services_api/service.rb +++ b/lib/data_services_api/service.rb @@ -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}", @@ -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 From f51bb2a05b8f38df12f01752a7e3b51fa12f66ca Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Tue, 1 Apr 2025 14:54:47 +0100 Subject: [PATCH 3/4] build: Updates version to 1.5.3 Increments the patch version cadence. --- lib/data_services_api/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data_services_api/version.rb b/lib/data_services_api/version.rb index 2731821..9c4d4eb 100644 --- a/lib/data_services_api/version.rb +++ b/lib/data_services_api/version.rb @@ -4,7 +4,7 @@ module DataServicesApi MAJOR = 1 MINOR = 5 - PATCH = 2 + PATCH = 3 SUFFIX = nil VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}#{SUFFIX && ".#{SUFFIX}"}" end From a8f7dbb07f0847d825e1c3b2102565c7f835eec2 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Tue, 1 Apr 2025 14:55:33 +0100 Subject: [PATCH 4/4] Docs: Updates changelog for v1.5.3 Updates the changelog to include details for the v1.5.3 release. --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce887df..43a8e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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