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 is dependent on config.IncludeErrorDetailPolicy configuration.
If I set config.IncludeErrorDetailPolicy
to IncludeErrorDetailPolicy.Always
, all the details are serialized into the HTTP response (Message
, ExceptionMessage
, ExceptionType
, and StackTrace
).
If I set config.IncludeErrorDetailPolicy
to IncludeErrorDetailPolicy.Never
, only the Message
is included.
However, I want to include the Message
, ExceptionMessage
, and ExceptionType
in the HTTP response but not the StackTrace
; how do I exclude only the StackTrace
? Or should I just concatenate the needed details into the Message field?
To add some context to my question, the client needs these exception details to handle special cases...but never the stack trace.