Module: RestApiGenerator::ErrorHandler

Defined in:
lib/rest_api_generator/error_handler.rb

Class Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



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

def self.included(clazz)
  clazz.class_eval do
    rescue_from ActiveRecord::RecordNotFound do |e|
      respond(:record_not_found, 404, e.to_s)
    end
    rescue_from ActiveRecord::ActiveRecordError do |e|
      respond(:active_record_error, 422, e.to_s)
    end
    rescue_from ActiveRecord::RecordInvalid do |e|
      respond(:active_record_invalid, 422, e.to_s)
    end
    rescue_from ActiveModel::ValidationError do |e|
      respond(:active_model_validation_error, 422, e.to_s)
    end
    rescue_from CustomError do |e|
      respond(e.error, e.status, e.message)
    end
  end
end