Error Handling for Invalid POST Data

I encountered a situation where submitting invalid data via a POST request resulted in a detailed stack trace being displayed in the response.

This behaviour poses a security risk ie exposing stack traces in responses can inadvertently disclose internal implementation details of the application and may aid malicious actors in targeting vulnerabilities.

Can we have this stack trace displayed only on debug flag true situations, else respond with a more user-friendly error message like Invalid request body rather than the trace.

Solved it by using Custom Error pages for 500 responses