You could replace error pages for WebApplication scope.
To replace custom error page you will need:
- Create application page for custom page (for ex. error.aspx) and place it to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\1033\ directory (for english locale)
Then if you prefer powershell run this script to map your page as web application custom error page:
$site = Get-SPSite "{site url}" -Limit All
$spWebApp = $site.WebApplication
$spWebApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error, "/_layouts/1033/error.aspx")
If you prefer code way you could use SPWebApplication.UpdateMappedPage method to map your page.
To get more information and examples check this posts:
How to customize SharePoint 2010 error pages
How to Customize Error Page, Page Not Found and Access Denied in SharePoint 2010
They describe solution for 2010 version but I think it should also work for SP 2013.