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 diff --git a/lib/data_services_api/service.rb b/lib/data_services_api/service.rb index b5cef91..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}", @@ -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( { @@ -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 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