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: Just a typo, sorry for that. Thank you for pointing me out on IncludeErrorDetailPolicy. The controller is synthetic (created by a controller factory in unit tests project) thus doesn't set the policy properly. I set it by it doesn't work still. Here's the code: ``` public static T Create<T>(params object[] args) where T : ApiController { var config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; var request = new HttpRequestMessage(); var routeData = new HttpRouteData(new HttpRoute()); T controller = (T)Activator.CreateInstance(typeof(T), args); controller.ControllerContext = new HttpControllerContext(config, routeData, request); controller.Request = request; controller.Request.Properties.Add(System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey, config); return controller; } ``` and ``` [TestMethod] public async Task GetDescription_Should_Return_Message_Having_ExceptionType_Set() { // Arrange var controller = CreateController(); var searchCriteria = new SearchCriteria(); // Act using (ControllerFactory.NewContext(ControllerFactory.CreateModelValidator(s => false))) { HttpResponseMessage message = await controller.GetDescription(searchCriteria); // Assert ObjectContent<HttpError> content = message.Content as ObjectContent<HttpError>; HttpError error = (HttpError)content.Value; Type type = Type.GetType(error.ExceptionType); type.Should().NotBeNull(); } } ```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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