Exception: Sipity::Exceptions::InvalidStateError

Inherits:
RuntimeError
  • Object
show all
Defined in:
app/exceptions/sipity/exceptions.rb

Overview

For some reason, you have an entity in an incorrect state. Push up what information we can to be helpful to the end user.

Direct Known Subclasses

InvalidDoiCreationRequestStateError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity:, actual:, expected: nil) ⇒ InvalidStateError

Returns a new instance of InvalidStateError


90
91
92
93
# File 'app/exceptions/sipity/exceptions.rb', line 90

def initialize(entity:, actual:, expected: nil)
  @entity, @actual, @expected = entity, actual, expected
  super(build_message)
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual


89
90
91
# File 'app/exceptions/sipity/exceptions.rb', line 89

def actual
  @actual
end

#entityObject (readonly)

Returns the value of attribute entity


89
90
91
# File 'app/exceptions/sipity/exceptions.rb', line 89

def entity
  @entity
end

#expectedObject (readonly)

Returns the value of attribute expected


89
90
91
# File 'app/exceptions/sipity/exceptions.rb', line 89

def expected
  @expected
end

Instance Method Details

#build_messageObject (private)


97
98
99
100
101
102
103
# File 'app/exceptions/sipity/exceptions.rb', line 97

def build_message
  if expected.present?
    "#{self.class}: Expected #{entity} to have state: #{expected}, but it had state: #{actual}"
  else
    "#{self.class}: #{entity} has in valid state: #{actual}"
  end
end