Switched to Phoenix and using the Custom Errors functionality
got it to work as required.
For the community in case any future finders, below is the link for it.
https://phoenixframework.readme.io/docs/custom-errors
Important : make sure you set debug_errors:
to false
in config/dev.exs
, to be able to see the custom message instead of the html error.
Hope it helps someone.