Iteration E2: Handling Errors
It’s apparent from the screenshot that our application raised an exception at line 63 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 to the outside ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access