X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f2574ec2e4ddef03c9504cd58741e73426ea1b17..20c594c3c683a492132c0fc105241689ee116c10:/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 25e776a942..7574cf665b 100644 --- a/apps/workbench/app/models/arvados_api_client.rb +++ b/apps/workbench/app/models/arvados_api_client.rb @@ -6,6 +6,8 @@ class ArvadosApiClient end class InvalidApiResponseException < StandardError end + class AccessForbiddenException < StandardError + end @@profiling_enabled = Rails.configuration.profiling_enabled @@discovery = nil @@ -13,7 +15,14 @@ class ArvadosApiClient # An API client object suitable for handling API requests on behalf # of the current thread. def self.new_or_current - Thread.current[:arvados_api_client] ||= new + # If this thread doesn't have an API client yet, *or* this model + # has been reloaded since the existing client was created, create + # a new client. Otherwise, keep using the latest client created in + # the current thread. + unless Thread.current[:arvados_api_client].andand.class == self + Thread.current[:arvados_api_client] = new + end + Thread.current[:arvados_api_client] end def initialize *args @@ -92,7 +101,11 @@ class ArvadosApiClient if msg.status_code != 200 errors = resp[:errors] errors = errors.join("\n\n") if errors.is_a? Array - raise "#{errors} [API: #{msg.status_code}]" + if msg.status_code == 403 + raise AccessForbiddenException.new "#{errors} [API: #{msg.status_code}]" + else + raise "#{errors} [API: #{msg.status_code}]" + end end if resp[:_profile] Rails.logger.info "API client: " \