Skip to content

Commit

Permalink
Added more exception handling around HttpContext.Request, since resov…
Browse files Browse the repository at this point in the history
…ling it might fail. Hopefully fixes getsentry#64.
  • Loading branch information
asbjornu committed Dec 5, 2014
1 parent 06fc749 commit 7c98a6a
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/app/SharpRaven/Data/SentryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,43 @@ public SentryUser GetUser()
if (!HasHttpContext)
return null;

return new SentryUser(HttpContext.User as IPrincipal)
return new SentryUser(GetPrincipal())
{
IpAddress = HttpContext.Request.UserHostAddress
IpAddress = GetIpAddress()
};
}


private static IPrincipal GetPrincipal()
{
try
{
return HttpContext.User as IPrincipal;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return null;
}


private static dynamic GetIpAddress()
{
try
{
return HttpContext.Request.UserHostAddress;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return null;
}


private static void GetHttpContext()
{
if (HasHttpContext)
Expand Down

0 comments on commit 7c98a6a

Please sign in to comment.