Getting Error establishing a database connection For sub sites that do not exists

For sub sites that do not exists I'm getting the following error

"Error establishing a database connection"

Instead of being redirected back to the main site homepage.