else
@errors = [e.to_s]
end
- # If the user has an active session, and the API server is available,
- # make user information available on the error page.
+ # Make user information available on the error page, falling back to the
+ # session cache if the API server is unavailable.
begin
load_api_token(session[:arvados_api_token])
rescue ArvadosApiClient::ApiError
- load_api_token(nil)
+ unless session[:user].nil?
+ begin
+ Thread.current[:user] = User.new(session[:user])
+ rescue ArvadosApiClient::ApiError
+ # This can happen if User's columns are unavailable. Nothing to do.
+ end
+ end
end
- # Preload projects trees for the template. If that fails, set empty
+ # Preload projects trees for the template. If that's not doable, set empty
# trees so error page rendering can proceed. (It's easier to rescue the
# exception here than in a template.)
- begin
- build_project_trees
- rescue ArvadosApiClient::ApiError
- @my_project_tree ||= []
- @shared_project_tree ||= []
+ unless current_user.nil?
+ begin
+ build_project_trees
+ rescue ArvadosApiClient::ApiError
+ # Fall back to the default-setting code later.
+ end
end
+ @my_project_tree ||= []
+ @shared_project_tree ||= []
render_error(err_opts)
end
false # We may redirect to login, or not, based on the current action.
else
session[:arvados_api_token] = params[:api_token]
+ session[:user] = {
+ uuid: user.uuid,
+ email: user.email,
+ first_name: user.first_name,
+ last_name: user.last_name,
+ is_active: user.is_active,
+ is_admin: user.is_admin,
+ prefs: user.prefs
+ }
if !request.format.json? and request.method.in? ['GET', 'HEAD']
# Repeat this request with api_token in the (new) session
get(:show, {id: "zzzzz-zzzzz-zzzzzzzzzzzzzzz"}, session_for(:admin))
assert_response 404
end
+
+ test "Workbench returns 4xx when API server is unreachable" do
+ # We're really testing ApplicationController's render_exception.
+ # Our primary concern is that it doesn't raise an error and
+ # return 500.
+ orig_api_server = Rails.configuration.arvados_v1_base
+ begin
+ # The URL should look valid in all respects, and avoid talking over a
+ # network. 100::/64 is the IPv6 discard prefix, so it's perfect.
+ Rails.configuration.arvados_v1_base = "https://[100::f]:1/"
+ @controller = NodesController.new
+ get(:index, {}, session_for(:active))
+ assert_includes(405..422, @response.code.to_i,
+ "bad response code when API server is unreachable")
+ ensure
+ Rails.configuration.arvados_v1_base = orig_api_server
+ end
+ end
end