TIL
find vs find_by to avoid noisy errors
Our error tracker was full of RecordNotFound exceptions for cases that were completely fine. A missing row was expected, not a real problem.
The cause was .find. In Rails, .find raises RecordNotFound when the row is not there, and that exception bubbles up into the tracker.
If absence is a normal outcome, use .find_by instead. It returns nil, and you handle the nil yourself:
user = User.find_by(id: params[:id])
return head :not_found if user.nil?
Swapping .find for .find_by where missing rows are expected cut a lot of error noise. Keep .find for the cases where a missing row really is a bug.