I know that I can override the standard error pages for a Force.com Site (Not Found, In Maintenance, Generic Error) with my own Visualforce pages and controller.
However, what I don't know how to do is find out what the root cause is for the Generic Error that is causing me to arrive at the page.
For example, if I haven't authorized one of the VF Pages that makes up my site to the Sites Guest User (via Profile or Permission Set), you land on the "http://xyz-developer-edition.na16.force.com/ticket is under construction. Stay tuned. Please email us if you need to get in touch." page.
But how do I know that the reason I'm on the Generic Error page is because of that specific problem?
My goal is to add a VF controller to the error page and email an administrator with a detailed explanation of the problem (and tips on how to resolve it).
Best Answer
After a long and laborious Case with Support, the conclusion is that there is no way to do what's suggested in the Question.
Any unhandled exception in a VF page served from Force.com Sites results in a 401/Unauthorized which is handled by the VF page configured as the "Unauthorized" handler in the Sites configuration.
If you add a Controller to this page and set an action on the page which invokes a method like so:
The ERROR MESSAGE is "Login is required to access this URL."
This is not correct, but according to Support, this is "working as designed" and as such, is completely useless.