Skip to content

Instantly share code, notes, and snippets.

@1dolinski
Created October 30, 2019 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1dolinski/2235c0a29ed067a7731917c2698b4c8b to your computer and use it in GitHub Desktop.
Save 1dolinski/2235c0a29ed067a7731917c2698b4c8b to your computer and use it in GitHub Desktop.
# WORKS: Hits the appropriate blocks
def self.included(clazz) #includes module as a class method
clazz.class_eval do
rescue_from StandardError do |e|
respond(:standard_error, 500, e.to_s)
end
rescue_from ActiveRecord::RecordNotFound do |e|
respond(:record_not_found, 404, e.to_s)
end
rescue_from CustomError do |e|
respond(e.error, e.status, e.message.to_s)
end
end
end
# DOES NOT WORK: Always just hits the Standard Error block
def self.included(clazz) #includes module as a class method
clazz.class_eval do
rescue_from ActiveRecord::RecordNotFound do |e|
respond(:record_not_found, 404, e.to_s)
end
rescue_from CustomError do |e|
respond(e.error, e.status, e.message.to_s)
end
rescue_from StandardError do |e|
respond(:standard_error, 500, e.to_s)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment