Skip to content

Commit

Permalink
Fixed an issue where code could throw due to CurrentUser
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Dec 18, 2024
1 parent b4e714d commit 33171cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Exceptionless.Core/Configuration/CacheOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static CacheOptions ReadFromConfiguration(IConfiguration config, AppOptio
options.Data.AddRange(providerOptions);
}

options.ConnectionString = options.Data.BuildConnectionString([ nameof(options.Provider) ]);
options.ConnectionString = options.Data.BuildConnectionString([nameof(options.Provider)]);

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ protected int GetSkip(int currentPage, int limit)
return skip;
}

/// <summary>
/// This call will throw an exception if the user is a token auth type.
/// This is less than ideal, and we should refactor this to be a nullable user.
/// NOTE: The only endpoints that allow token auth types is
/// - post event
/// - post user event description
/// - post session heartbeat
/// - post session end
/// - project config
/// </summary>
protected virtual User CurrentUser => Request.GetUser();

protected bool CanAccessOrganization(string organizationId)
Expand Down
16 changes: 8 additions & 8 deletions src/Exceptionless.Web/Controllers/EventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ private async Task<ActionResult<CountResult>> CountInternalAsync(AppFilter sf, T
}
catch (Exception ex)
{
using (_logger.BeginScope(new ExceptionlessState().Property("Search Filter", new { SystemFilter = sf, UserFilter = filter, Time = ti, Aggregations = aggregations }).Tag("Search").Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).SetHttpContext(HttpContext)))
_logger.LogError(ex, "An error has occurred. Please check your filter or aggregations");
using var _ = _logger.BeginScope(new ExceptionlessState().Property("Search Filter", new { SystemFilter = sf, UserFilter = filter, Time = ti, Aggregations = aggregations }).Tag("Search").Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).SetHttpContext(HttpContext));
_logger.LogError(ex, "An error has occurred. Please check your filter or aggregations: {Message}", ex.Message);

throw;
}
Expand Down Expand Up @@ -867,8 +867,8 @@ await Task.WhenAll(
{
if (projectId != _appOptions.InternalProjectId)
{
using (_logger.BeginScope(new ExceptionlessState().Project(projectId).Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).Property("Id", id).Property("Close", close).SetHttpContext(HttpContext)))
_logger.LogError(ex, "Error enqueuing session heartbeat");
using var _ = _logger.BeginScope(new ExceptionlessState().Project(projectId).Property("Id", id).Property("Close", close).SetHttpContext(HttpContext));
_logger.LogError(ex, "Error enqueuing session heartbeat: {Message}", ex.Message);
}

throw;
Expand Down Expand Up @@ -1127,8 +1127,8 @@ await _eventPostService.EnqueueAsync(new EventPost(_appOptions.EnableArchive)
{
if (projectId != _appOptions.InternalProjectId)
{
using (_logger.BeginScope(new ExceptionlessState().Project(projectId).Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).SetHttpContext(HttpContext)))
_logger.LogError(ex, "Error enqueuing event post");
using var _ = _logger.BeginScope(new ExceptionlessState().Project(projectId).SetHttpContext(HttpContext));
_logger.LogError(ex, "Error enqueuing event post: {Message}", ex.Message);
}

throw;
Expand Down Expand Up @@ -1328,8 +1328,8 @@ await _eventPostService.EnqueueAsync(new EventPost(_appOptions.EnableArchive)
{
if (projectId != _appOptions.InternalProjectId)
{
using (_logger.BeginScope(new ExceptionlessState().Project(projectId).Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).SetHttpContext(HttpContext)))
_logger.LogError(ex, "Error enqueuing event post");
using var _ = _logger.BeginScope(new ExceptionlessState().Project(projectId).SetHttpContext(HttpContext));
_logger.LogError(ex, "Error enqueuing event post: {Message}", ex.Message);
}

throw;
Expand Down

0 comments on commit 33171cf

Please sign in to comment.