in my config/initializers , I created the file custom_exceptions.rb
in which I put all my custom exceptions
..
module Exceptions
class MyLockerException < StandardError
def initialize(msg, error_code , member_id )
super(msg)
@message = msg
@error_code = error_code
@member_id = member_id
end
def message
@message + ", member: #{@member_id} , ERROR: #{@error_code}"
end
def error_code
@error_code
end
def member_id
@member_id
end
end
...
I have a Delayed_job script , in which I raise the exceptions like
this :
...
raise Exceptions::MyLockerException.new("MyLockerException",
error_code, locker[:id], member[:id], ) if analysis.nil?
..
when the exception is raised , it's catch by the error method
in my config/initializers , I created the file custom_exceptions.rb
in which I put all my custom exceptions
..
module Exceptions
class MyLockerException < StandardError
def initialize(msg, error_code , member_id )
super(msg)
@message = msg
@error_code = error_code
@member_id = member_id
end
def message
@message \+ ", member: \#\{@member\_id\} , ERROR: \#\{@error\_code\}"
end
def error\_code
@error\_code
end
def member\_id
@member\_id
end
end
...
I have a Delayed_job script , in which I raise the exceptions like
this :
...
raise Exceptions::MyLockerException.new("MyLockerException",
error_code, locker[:id], member[:id], ) if analysis.nil?
..
when the exception is raised , it's catch by the error method
solved ... not related to exception .. correctly passed and raised,
but rather related to a bad delayed_job struct definition
class InstructionRequestJob <
Struct.new(:param1, :param2, :param3, :error)
but I enqueued it w only 2 parameters :
Delayed::Job.enqueue InstructionRequestJob.new( param1, param2)
so got issue with the DJ :error catch...
writing : Delayed::Job.enqueue InstructionRequestJob.new( param1,
param2, params3) solved the issue :
def error(job, exception)
..
error_code = exception.error_code # or anything else stored in
the exception...
...
end
catching correctly the raised exception ...