Class: RepeatedStateChangeError

Inherits:
Sequencescape::Api::ConnectionFactory::Actions::ServerError
  • Object
show all
Defined in:
lib/repeated_state_change_error.rb

Overview

This class rescues any exceptions where the source and target states are the same but the transition is invalid.

Class Method Summary collapse

Class Method Details

.===(other) ⇒ Object

rescue automatically uses the match operator (===) to identify exceptions to rescue



7
8
9
# File 'lib/repeated_state_change_error.rb', line 7

def self.===(other)
  other.is_a?(Sequencescape::Api::ConnectionFactory::Actions::ServerError) && repeated_state_change_error?(other)
end

.repeated_state_change_error?(exception) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/repeated_state_change_error.rb', line 11

def self.repeated_state_change_error?(exception)
  error = JSON.parse(exception.message).dig('general', 0)
  match_data = /\ANo obvious transition from "([^"]+)" to "([^"]+)"\z/.match(error)
  (match_data || false) && match_data[1] == match_data[2]
end