Create an errors.php which can be called like
<PGV>/errors.php?errcode=404&subcode=.....
This should do the header and footer appropriate to theme and lang with content like (sorry this #$%^#$%^ tracker
discards spaces!):
case errcode
403: case subcode
string1:
string2:
generic:
404: etc.
generic: etc.
generic meaning the code or subcode hasn't been explicitly coded.
Calling script could pass on any other parameters that the error script could use if appropriate.
At least one of the 404 subcodes should include an appropriate handling for attempts to fetch non-existent records. Currently, sometimes PGV says the record is private (even to admins!) and sometimes the webserver just sends a generic 404.
Some places already have good error handling which could be left where it is or moved into this.
Other places explicitly simulate a webserver's 403, 4040, etc. Those would be a case-by-case decision whether to remain that way or handle this way.
(Handling a 403 by a complicated script instead of
err-and-exit might be a security risk in the case of directly calling an include file. But not if it's a matter of clicking a link that's not in your list of privileges.)