PureKrome / WorldDomination.Web.Mvc.ErrorHandling

13 stars 6 forks source link

NullReferenceException when HttpContext.Current.Error is null #5

Open wwuck opened 11 years ago

wwuck commented 11 years ago

I'm getting a NullReferenceException appearing when HttpContext.Current.Error is null. It only seems to happen for me when I do a request to a Web-Api controller that requires authentication, and the user hasn't yet authenticated via forms auth. Adding in a check for null values on currentError appears to resolve the problem and Web-Api then returns the correct 401 response.

CustomErrorHandlingModule.cs#L98

I'll try to submit a pull request after I work out how to use git.

PureKrome commented 11 years ago

Fixed and new nuget package (v2.2.1) pushed up. try that.

wwuck commented 11 years ago

That commit doesn't appear to check for a nullref on HttpContext.Current.Error. During my testing I found that HttpContext.Current wasn't null, only HttpContext.Current.Error. Still good to have the nullref check on HttpContext.Current though.

PureKrome commented 11 years ago

Hmm. weird. So an error has occurred ... but we don't have an error.

I've updated the code and pushed a new package up. test away!

wwuck commented 11 years ago

Looks like that fixes the errors I was seeing. Thanks!