mirror of
https://github.com/ditkrg/workflower.git
synced 2026-01-22 14:17:11 +00:00
Merge pull request #9 from arikarim/dev
Enhance error handling in manager.rb by logging error messages and cl…
This commit is contained in:
commit
688bcdaaf5
@ -3,7 +3,25 @@
|
|||||||
require_relative "workflower/version"
|
require_relative "workflower/version"
|
||||||
require "workflower/manager"
|
require "workflower/manager"
|
||||||
require "workflower/acts_as_workflower"
|
require "workflower/acts_as_workflower"
|
||||||
|
|
||||||
module Workflower
|
module Workflower
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
# Your code goes here...
|
|
||||||
|
class << self
|
||||||
|
def configuration
|
||||||
|
@configuration ||= Configuration.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def configure
|
||||||
|
yield(configuration)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Configuration
|
||||||
|
attr_accessor :logger
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@logger = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,7 +37,6 @@ module Workflower
|
|||||||
end
|
end
|
||||||
|
|
||||||
def possible_transitions
|
def possible_transitions
|
||||||
# @transitions.where(state: @current_state).where("sequence = :seq OR sequence = :seq_plus", seq: @current_sequence, seq_plus: @current_sequence + 1).order("sequence ASC") || []
|
|
||||||
@transitions.select do |item|
|
@transitions.select do |item|
|
||||||
item[:state] == @current_state && (item[:sequence] == @current_sequence || item[:sequence] == @current_sequence + 1)
|
item[:state] == @current_state && (item[:sequence] == @current_sequence || item[:sequence] == @current_sequence + 1)
|
||||||
end
|
end
|
||||||
@ -61,7 +60,11 @@ module Workflower
|
|||||||
@calling_model.assign_attributes flow.updateable_attributes(@calling_model)
|
@calling_model.assign_attributes flow.updateable_attributes(@calling_model)
|
||||||
flow.call_after_transition(@calling_model)
|
flow.call_after_transition(@calling_model)
|
||||||
true
|
true
|
||||||
rescue Exception
|
rescue Exception => e
|
||||||
|
# if the log level is set to debug, we want to log the error
|
||||||
|
logger = Workflower.configuration.logger
|
||||||
|
logger.debug("Error during transition: #{e.message}") if logger.present?
|
||||||
|
|
||||||
@calling_model.errors.add(@calling_model.workflower_state_column_name, :transition_faild)
|
@calling_model.errors.add(@calling_model.workflower_state_column_name, :transition_faild)
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Workflower
|
module Workflower
|
||||||
VERSION = "0.2.6"
|
VERSION = "0.2.7"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user