lib/floe/workflow/catcher.rb in floe-0.11.3 vs lib/floe/workflow/catcher.rb in floe-0.12.0
- old
+ new
@@ -1,17 +1,31 @@
# frozen_string_literal: true
module Floe
class Workflow
class Catcher
- attr_reader :error_equals, :next, :result_path
+ include ErrorMatcherMixin
+ include ValidationMixin
- def initialize(payload)
- @payload = payload
+ attr_reader :error_equals, :next, :result_path, :name
+ def initialize(workflow, name, payload)
+ @name = name
+ @payload = payload
+
@error_equals = payload["ErrorEquals"]
@next = payload["Next"]
@result_path = ReferencePath.new(payload.fetch("ResultPath", "$"))
+
+ missing_field_error!("ErrorEquals") if !@error_equals.kind_of?(Array) || @error_equals.empty?
+ validate_state_next!(workflow)
+ end
+
+ private
+
+ def validate_state_next!(workflow)
+ missing_field_error!("Next") if @next.nil?
+ invalid_field_error!("Next", @next, "is not found in \"States\"") if @next && !workflow_state?(@next, workflow)
end
end
end
end