41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/api_rescuable.rb', line 41
def rescue_from_api(*klasses)
rescuer = {
ActiveRecord::RecordNotFound => :handle_record_not_found,
ActiveRecord::RecordInvalid => :handle_record_invalid,
ActiveModel::ForbiddenAttributesError => :handle_forbidden_attributes,
ActionController::ParameterMissing => :handle_parameter_missing,
CanCan::AccessDenied => :handle_unauthorized_access,
}
klasses.each do |klass|
rescue_from klass, with: rescuer[klass]
end
(rescuer.keys - klasses).each do |klass|
undef_method rescuer[klass]
end
end
|