In my MVC WebApi service, when an exception is thrown, it is handled by a filter:
public class GlobalExceptionFilter : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext context) { context.Response = context.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request", context.Exception); } }
This HTTP response generated by this filter depends on the configuration of config.IncludeErrorDetailPolicy.
If I set config.IncludeErrorDetailPolicy to IncludeErrorDetailPolicy.Always , all details are serialized in an HTTP response ( Message , ExceptionMessage , ExceptionType and StackTrace ).
If I set config.IncludeErrorDetailPolicy to IncludeErrorDetailPolicy.Never , only Message included.
However, I want to include Message , ExceptionMessage and ExceptionType in the HTTP response, but not StackTrace ; How can I exclude only StackTrace ? Or should I just concatenate the necessary data in the Message field?
To add some context to my question, the client needs these exception details to handle special cases ... but never a stack trace.
source share