Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Rails 7.1 Now Allows ErrorReporter To Handle Several Error Classes

I'm a React and Rails enthusiast with two years of experience creating innovative software solutions that improve business productivity. I work well in teams and am always up for challenging projects. Born and raised in Navi Mumbai, I enjoy gaming and travelling in my free time.Recently Rails introduced a new way of handling errors which removes the need of using begin..end and makes handling of multiple errors much more easier to read and write.Read more about ErrorReporting API from hereFor using Error reporter we need an error subscriber.A Subscriber is any object with a report method defined in it. Let’s have a look -The above code subscribes to our custom ErrorSubscriber class which reports errors coming from our ErrorService.Prior to the addition of error handler in Rails we used begin...end block and rescue any errors being reported which were logged in the Rails console.Rescue with multiple exceptions -After the change introduced in this PR, it is now possible to replace the above syntax with the handle method.If the block does not raise any Exception/Error then result of the block will be returned or else it returns nil.We can override this by providing fallback which returns the fallback value if any error is raised instead of returning nil -Read about more options supported by ErrorHandler handle method from hereNeed help on your Ruby on Rails or React project?If you enjoyed this post, you might also like:November 3, 2022September 2, 2019July 28, 2023Join Our NewsletterThanks! Your subscription has been confirmed.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Rails 7.1 Now Allows ErrorReporter To Handle Several Error Classes

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×