Module: ServiceExtend::Handler

Defined in:
lib/service_extend/handler.rb

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/service_extend/handler.rb', line 4

def call
  if defined?(::Rails::Engine) && defined?(::ActiveRecord)
    begin
      super
    rescue ServiceError => e
      @error = e
    rescue ActiveRecord::RecordNotFound => e
      @error = ServiceError.new(:record_not_found, error_message: e.message)
      @error.set_backtrace(e.backtrace)
    rescue Exception => e
      @error = ServiceError.generate_from_exception(e)
    end
  else
    begin
      super
    rescue ServiceError => e
      @error = e
    rescue Exception => e
      @error = ServiceError.generate_from_exception(e)
    end
  end
end