Commit 640a1efc authored by MARGERY David's avatar MARGERY David
Browse files

Handle Grit::Git::GitTimeout gracefully in find

Grid5000::repository.find can now return exception

returning nil implies the object was not found
returning an Exception implies something unexpected happened when
looking for the object
parent f51ca709
......@@ -35,6 +35,7 @@ class ApplicationController < ActionController::Base
class ServerError < ActionController::ActionControllerError; end
class UnsupportedMediaType < ServerError; end # Error code 415 (moved to server-side)
class BadGateway < ServerError; end # Error code 50x (to be refined later)
class ServerUnavailable < ServerError; end # Error code 503
# This thing must alway come first, or it will override other rescue_from.
rescue_from Exception, :with => :server_error
......@@ -54,6 +55,7 @@ class ApplicationController < ActionController::Base
# abasu : agreed to send exception to server_error (instead of unsupported_media_type)
rescue_from ServerError, :with => :server_error # for 500
rescue_from BadGateway, :with => :bad_gateway # for 502
rescue_from ServerUnavailable, :with => :server_unavailable # for 503
protected
def set_default_format
......@@ -132,6 +134,8 @@ class ApplicationController < ActionController::Base
raise UnsupportedMediaType, msg
when 502
raise BadGateway, msg
when 503
raise ServerUnavailable, msg
else
raise ServerError, "Request to #{http.last_effective_url.to_s} failed with status #{status}: #{http.response}"
Rails.logger.error msg
......@@ -254,6 +258,12 @@ class ApplicationController < ActionController::Base
render_error(exception, opts)
end
def server_unavailable(exception)
opts = {:status => 503}
opts[:message] = "Server Unavailable" if exception.message == exception.class.name
render_error(exception, opts)
end
# ================
# = HTTP Headers =
# ================
......
......@@ -104,6 +104,8 @@ class ResourcesController < ApplicationController
:branch => params[:branch],
:version => params[:version]
)
raise ServerUnavailable if object.is_a?(Exception)
# abasu : case logic for treating different scenarios - 11.12.2015
case [params[:controller], params[:action]]
......
......@@ -39,12 +39,17 @@ module Grid5000
logger.info "path = #{path.inspect}, options = #{options.inspect}"
path = full_path(path)
@commit = nil
@commit = find_commit_for(options)
logger.info "commit = #{@commit.inspect}"
return nil if @commit.nil?
object = find_object_at(path, @commit)
logger.debug "object = #{object.inspect}"
return nil if object.nil?
begin
@commit = find_commit_for(options)
logger.info "commit = #{@commit.inspect}"
return nil if @commit.nil?
object = find_object_at(path, @commit)
logger.debug "object = #{object.inspect}"
return nil if object.nil?
rescue Grit::Git::GitTimeout => e
logger.debug "#{Time.now}: Got a Grit::Git::GitTimeout exception #{e}"
return e
end
result = expand_object(object, path, @commit)
result
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment