X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b40c9953d3f925ff507e1780d9970b632a819907..d199bf8a0732563a65f19538c6fa66b00f820f66:/apps/workbench/app/models/arvados_api_client.rb diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb index f36627f07b..78d3beef3c 100644 --- a/apps/workbench/app/models/arvados_api_client.rb +++ b/apps/workbench/app/models/arvados_api_client.rb @@ -8,10 +8,21 @@ class ArvadosApiClient def initialize(request_url, errmsg) @request_url = request_url @api_response ||= {} + errors = @api_response[:errors] + if not errors.is_a?(Array) + @api_response[:errors] = [errors || errmsg] + end super(errmsg) end end + class NoApiResponseException < ApiError + def initialize(request_url, exception) + @api_response_s = exception.to_s + super(request_url, + "#{exception.class.to_s} error connecting to API server") + end + end class InvalidApiResponseException < ApiError def initialize(request_url, api_response) @@ -115,9 +126,11 @@ class ArvadosApiClient profile_checkpoint { "Prepare request #{url} #{query[:uuid]} #{query[:where]} #{query[:filters]}" } msg = @client_mtx.synchronize do - @api_client.post(url, - query, - header: header) + begin + @api_client.post(url, query, header: header) + rescue => exception + raise NoApiResponseException.new(url, exception) + end end profile_checkpoint 'API transaction' @@ -129,7 +142,8 @@ class ArvadosApiClient if not resp.is_a? Hash raise InvalidApiResponseException.new(url, msg) elsif msg.status_code != 200 - error_class = ERROR_CODE_CLASSES.fetch(msg.status_code, ApiError) + error_class = ERROR_CODE_CLASSES.fetch(msg.status_code, + ApiErrorResponseException) raise error_class.new(url, msg) end