Module: Jumbotron::Public::TranslateOutcome
- Defined in:
- app/models/jumbotron/public/translate_outcome.rb
Constant Summary collapse
- NOT_FOUND_CODES =
%w[ not_found game_not_found league_not_found season_not_found season_phase_not_found schedule_group_not_found ].freeze
Class Method Summary collapse
- .call(result, payload_key:) ⇒ Object
- .error_code_and_message(result) ⇒ Object
- .exception_class_for(code) ⇒ Object
- .public_error_for(result) ⇒ Object
Class Method Details
.call(result, payload_key:) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/models/jumbotron/public/translate_outcome.rb', line 17 def call(result, payload_key:) unless result.is_a?(CommandTower::Workflows::WorkflowResult) raise Jumbotron::Error, "unexpected internal result" end return result.payload.fetch(payload_key) if result.success? raise public_error_for(result) end |
.error_code_and_message(result) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/jumbotron/public/translate_outcome.rb', line 34 def (result) error = Array(result.errors).first case error when CommandTower::Errors::ApplicationError [error.code.to_s, error.] when Hash [(error[:code] || error["code"]).to_s, (error[:message] || error["message"]).to_s] else ["internal_error", error.to_s] end end |
.exception_class_for(code) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/models/jumbotron/public/translate_outcome.rb', line 47 def exception_class_for(code) return Jumbotron::NotFoundError if NOT_FOUND_CODES.include?(code) return Jumbotron::InvalidRequestError if code == "invalid_request" return Jumbotron::UnsupportedCapabilityError if code == "unsupported" Jumbotron::Error end |
.public_error_for(result) ⇒ Object
27 28 29 30 31 |
# File 'app/models/jumbotron/public/translate_outcome.rb', line 27 def public_error_for(result) code, = (result) klass = exception_class_for(code) klass.new() end |