Skip to content

Commit

Permalink
Catch SqlExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Sep 13, 2023
1 parent dcdb9c0 commit fa1b098
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Claims;
using System.Threading;
Expand Down Expand Up @@ -460,14 +461,21 @@ private void FillSampledTransactionContextUser(HttpContext context, ITransaction

if (context.User is ClaimsPrincipal claimsPrincipal)
{
static string GetClaimWithFallbackValue(ClaimsPrincipal principal, string claimType, string fallbackClaimType)
try
{
var claim = principal.Claims.FirstOrDefault(n => n.Type == claimType || n.Type == fallbackClaimType);
return claim != null ? claim.Value : string.Empty;
}
static string GetClaimWithFallbackValue(ClaimsPrincipal principal, string claimType, string fallbackClaimType)
{
var claim = principal.Claims.FirstOrDefault(n => n.Type == claimType || n.Type == fallbackClaimType);
return claim != null ? claim.Value : string.Empty;
}

user.Email = GetClaimWithFallbackValue(claimsPrincipal, ClaimTypes.Email, OpenIdClaimTypes.Email);
user.Id = GetClaimWithFallbackValue(claimsPrincipal, ClaimTypes.NameIdentifier, OpenIdClaimTypes.UserId);
user.Email = GetClaimWithFallbackValue(claimsPrincipal, ClaimTypes.Email, OpenIdClaimTypes.Email);
user.Id = GetClaimWithFallbackValue(claimsPrincipal, ClaimTypes.NameIdentifier, OpenIdClaimTypes.UserId);
}
catch (SqlException ex)
{
_logger.Error()?.Log("Unable to access user claims due to SqlException with message: {message}", ex.Message);
}
}

transaction.Context.User = user;
Expand Down

0 comments on commit fa1b098

Please sign in to comment.