In Cloudflare? The redirect has to happen in Cloudflare since Cloudflare is unable to load your origin site using the www name.
Are you using a Page Rule or a Bulk Redirect? If you want to share the rule, I’m happy to see if it looks like there is anything that might be preventing it from behaving as expected.
I no longer get the Cloudflare error page, but instead see a 403 Forbidden returned.