module Exceptionally::Controller
Public Instance Methods
exceptionally_handler(error)
click to toggle source
Raise custom error
# File lib/exceptionally/controller.rb, line 18 def exceptionally_handler(error) pass_to_error_handler(error) end
missing_param_handler(error)
click to toggle source
Raise 400 error
# File lib/exceptionally/controller.rb, line 23 def missing_param_handler(error) pass_to_error_handler(error, 400) end
missing_record_handler(error)
click to toggle source
Raise 404 error
# File lib/exceptionally/controller.rb, line 28 def missing_record_handler(error) pass_to_error_handler(error, 404) end
pass_to_error_handler(error, status = nil, extra = {})
click to toggle source
# File lib/exceptionally/controller.rb, line 42 def pass_to_error_handler(error, status = nil, extra = {}) status ||= error.try(:status) || 500 Exceptionally::Handler.new(error.message, status, error, params) render_error(error, status, extra) end
record_invalid_handler(error)
click to toggle source
Raise 409 error
# File lib/exceptionally/controller.rb, line 33 def record_invalid_handler(error) pass_to_error_handler(error, 409) end
record_not_saved(error)
click to toggle source
Raise 422 error
# File lib/exceptionally/controller.rb, line 38 def record_not_saved(error) pass_to_error_handler(error, 422, {validations: error.record.try(:errors)}) end
render_error(error, status = 500, extra = {})
click to toggle source
# File lib/exceptionally/controller.rb, line 48 def render_error(error, status = 500, extra = {}) render json: {error: error.message}.merge(extra || {}), status: status || 500 end