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.



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gin/errorable.rb', line 105

def handle_error err
  (@env[Gin::Constants::GIN_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.



123
124
125
126
# File 'lib/gin/errorable.rb', line 123

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