This was previously broken by 59ef48c0b9d70a6639a545d1c96f3cc6f93ebf2c (#11425, #11424, Error page appears repeatedly after you try accessing a private page - bug - Discourse Meta).
Centralize the logic into the exception controller, which avoids the problematic bug and makes it easy to add additional detailed 404 pages in the future.
This commit is a localization break. Translators should copy the
not_in_group.title_topic key to the
not_in_group.title_category key, changing “topic” to “category”.