Module: Mojito::Helpers::ExceptionHandling

Defined in:
lib/mojito/helpers/exception_handling.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(type) ⇒ Object



24
25
26
# File 'lib/mojito/helpers/exception_handling.rb', line 24

def self.included(type)
  type.extend ClassMethods
end

Instance Method Details

#__handle_error(exception) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mojito/helpers/exception_handling.rb', line 40

def __handle_error(exception)
  if handler = case exception
    when MojitoException
      response.status = exception.status
      self.class.error_handlers[exception.status]
    when Exception
      self.class.error_handlers[exception.class]
    end
    instance_exec &handler
  end
  raise exception
end

#raise(exception) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mojito/helpers/exception_handling.rb', line 28

def raise(exception)
  backtrace = caller[1..-1]
  Kernel.raise case exception
  when Symbol, Integer
    Mojito::MojitoException.new(exception)
  when Exception
    exception
  else
    RuntimeError.new(exception)
  end.tap {|e| e.set_backtrace backtrace }
end