Module: ViewModel::ErrorWrapping
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecord, ActiveRecord::UpdateContext, ActiveRecord::UpdateOperation
- Defined in:
- lib/view_model/error_wrapping.rb
Instance Method Summary collapse
-
#wrap_active_record_errors(blame) ⇒ Object
Catch and translate ActiveRecord errors that map to standard ViewModel errors.
Instance Method Details
#wrap_active_record_errors(blame) ⇒ Object
Catch and translate ActiveRecord errors that map to standard ViewModel errors. Blame may be either a single VM::Reference or an array of them, or an empty array if there is no specific node that the error may be attached to.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/view_model/error_wrapping.rb', line 11 def wrap_active_record_errors(blame) yield rescue ::ActiveRecord::RecordInvalid => e raise ViewModel::DeserializationError::Validation.from_active_model(e.record.errors, Array.wrap(blame)) rescue ::ActiveRecord::StaleObjectError => _e raise ViewModel::DeserializationError::LockFailure.new(Array.wrap(blame)) rescue ::ActiveRecord::QueryAborted, ::ActiveRecord::PreparedStatementCacheExpired, ::ActiveRecord::TransactionRollbackError => e raise ViewModel::DeserializationError::TransientDatabaseError.new(e., Array.wrap(blame)) rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::InvalidForeignKey, ::ActiveRecord::RecordNotSaved => e raise ViewModel::DeserializationError::DatabaseConstraint.from_exception(e, Array.wrap(blame)) end |