custom error message or redirect to custom page if any error occurs

Now, that’s actually pretty easy. Just create a 404.php and a 403.php and maybe a custom-error.php

Then you can setup your .htaccess with something like this:

ErrorDocument 500 /custom-error.php
ErrorDocument XXX /custom-error.php

Please remember: you do not need that for the 404 and 403 as these are actually supported by the WordPress Codex. For further Informations feel free to read the codex. Inside of the .php file you can do whatever.

Codex: https://codex.wordpress.org/Creating_an_Error_404_Page

Additional: https://premium.wpmudev.org/blog/customize-error-pages-wordpress/