Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: HttpError.ExceptionType is null [1248]

$
0
0
Having the following code:

return Request.CreateErrorResponse(
HttpStatusCode.BadRequest,
new ArgumentNullException("searchCriteria"));

I expect to be able to read ExceptionType back:

SearchCriteria searchCriteria = null;
HttpResponseMessage message = controller.Do(searchCriteria);

ObjectContent<HttpError> content = message.Content as ObjectContent<HttpError>;
HttpError error = (HttpError)content.Value;
string exceptionType = error.ExceptionType;

but the last line gives always `null`? Why is that?
Comments: In a test case, they key is that we look at the requestContext.IncludeErrorDetails Boolean property. Because of the way you are initializing the test, this property is not set correctly. In the runtime it's caching the value earlier, but in the test it's too late. So the fix to the test would be to grab the request context off the request, and set the includeerrordetails to true. ``` HttpRequestContext requestContext = (HttpRequestContext)(controller.Request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.RequestContextKey]); requestContext.IncludeErrorDetail = true; ``` or ``` request.SetRequestContext(new HttpRequestContext() { IncludeErrorDetail = true }); ```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>