22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/human_error/persistable.rb', line 22
def save!(*args)
super
rescue ActiveRecord::InvalidForeignKey => e
association_info_pattern = /DETAIL: Key \((.*)_id\)=\(([a-f0-9\-]+)\)/
association_name, association_id = e.message.
match(association_info_pattern) \
[1..-1]
raise HumanError::Errors::AssociationError.new(
resource_name: Persistable.human_error_resource_name(self.class),
association_name: association_name,
association_id: association_id,
attributes: attributes)
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
raise HumanError::Errors::ResourcePersistenceError.new(
resource_name: Persistable.human_error_resource_name(self.class),
attributes: attributes,
errors: errors.full_messages)
end
|