Created
October 30, 2019 21:42
-
-
Save 1dolinski/2235c0a29ed067a7731917c2698b4c8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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