Exception: ViewModel::DeserializationError::DatabaseConstraint

Inherits:
ViewModel::DeserializationError show all
Defined in:
lib/view_model/deserialization_error.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractErrorWithBlame

#nodes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ViewModel::DeserializationError

#code

Methods inherited from AbstractErrorWithBlame

#meta

Methods inherited from AbstractError

#aggregation?, #causes, #code, #exception, #meta, #status, #title, #to_s, #view

Constructor Details

#initialize(detail, nodes = []) ⇒ DatabaseConstraint

Returns a new instance of DatabaseConstraint.



367
368
369
370
# File 'lib/view_model/deserialization_error.rb', line 367

def initialize(detail, nodes = [])
  @detail = detail
  super(nodes)
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



365
366
367
# File 'lib/view_model/deserialization_error.rb', line 365

def detail
  @detail
end

Class Method Details

.from_exception(exception, nodes = []) ⇒ Object

Database constraint errors that come from Postgres are pretty opaque and stringly typed. We can do our best to parse out what metadata we can from the error, and fall back when we can’t.



375
376
377
378
379
380
381
382
# File 'lib/view_model/deserialization_error.rb', line 375

def self.from_exception(exception, nodes = [])
  case exception.cause
  when PG::UniqueViolation, PG::ExclusionViolation
    UniqueViolation.from_postgres_error(exception.cause, nodes)
  else
    self.new(exception.message, nodes)
  end
end