Module: Gin::Errorable

Extended by:
GinClass
Included in:
Controller
Defined in:
lib/gin/errorable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'lib/gin/errorable.rb', line 4

def self.included klass
  klass.extend ClassMethods
end

Instance Method Details

#handle_error(err) ⇒ Object

Calls the appropriate error handlers for the given error. Re-raises the error if no handler is found.



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gin/errorable.rb', line 91

def handle_error err
  (@env[Gin::App::RACK_KEYS[:errors]] ||= []) << err
  status(err.http_status) if err.respond_to?(:http_status)
  status(500) unless (400..599).include? status

  handler = error_handler_for(err)
  instance_exec(err, &handler) if handler

  ahandler = error_handler_for(:all)
  instance_exec(err, &ahandler) if ahandler

  raise err unless handler
end

#handle_status(code) ⇒ Object

Calls the appropriate error handlers for the given status code.



109
110
111
112
# File 'lib/gin/errorable.rb', line 109

def handle_status code
  handler = error_handler_for(code)
  instance_exec(&handler) if handler
end