Skip to content

Commit

Permalink
Gracefully handle null Bugsnag ApiKey
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Sep 11, 2024
1 parent 283e41d commit d3f83c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class BugsnagExceptionFilter : ExceptionFilterAttribute
public override void OnException(ExceptionContext context)
{
Bugsnag.IClient? client = context.HttpContext.RequestServices.GetService<Bugsnag.IClient>();
if (client?.Configuration.ApiKey == null)
{
return;
}
client?.Notify(context.Exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public class BugsnagOptions
{
public const string Key = "Bugsnag";

public string ApiKey { get; set; } = "";
public string? ApiKey { get; set; } = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ public static IServiceCollection AddBugSnag(this IServiceCollection services, IC
{
Console.WriteLine("BugSnag ApiKey not available - not adding BugSnag.");
}
else
services.AddBugsnag(configuration =>
{
services.AddBugsnag(configuration =>
{
configuration.ApiKey = apiKey;
});
}
configuration.ApiKey = apiKey;
});
return services;
}
}

0 comments on commit d3f83c7

Please sign in to comment.