Iteration E2: Handling Errors
It’s apparent from the page shown in the screenshot that our application raised an exception at line 67 of the carts controller. Your line number might be different, as we have some book-related formatting stuff in our source files. If you go to that line, you’ll find the following code:
| @cart = Cart.find(params[:id]) |
If the cart can’t be found, Active Record raises a RecordNotFound exception, which we clearly need to handle. The question arises—how?
We could silently ignore it. From a security standpoint, this is probably the best move, because it gives no information to a potential attacker. However, it also means that if we ever have a bug in our code that generates bad cart IDs, our application will appear ...
Get Agile Web Development with Rails 5, 1st Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.