Skip to content

Commit

Permalink
Option "IgnoreCanceledErrors"
Browse files Browse the repository at this point in the history
  • Loading branch information
anfomin committed Jun 27, 2018
1 parent f413c7d commit 2f3a215
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion RaygunCore.AspNetCore/Services/RaygunMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace RaygunCore.Services
{
Expand All @@ -26,7 +27,9 @@ public async Task Invoke(HttpContext httpContext)
catch (Exception ex)
{
var client = httpContext.RequestServices.GetRequiredService<IRaygunClient>();
await client.SendAsync(ex, RaygunSeverity.Critical);
var opt = httpContext.RequestServices.GetRequiredService<IOptions<RaygunOptions>>().Value;
if (!opt.IgnoreCanceledErrors || !(ex is OperationCanceledException))
await client.SendAsync(ex, RaygunSeverity.Critical);
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RaygunCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RepositoryUrl>https://github.com/anfomin/rayguncore</RepositoryUrl>
<PackageProjectUrl>https://github.com/anfomin/rayguncore</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/anfomin/rayguncore/blob/master/LICENSE</PackageLicenseUrl>
<VersionPrefix>1.0.2</VersionPrefix>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionSuffix Condition="'$(VERSION_SUFFIX)'!=''">$(VERSION_SUFFIX)</VersionSuffix>
<NoWarn>$(NoWarn);1573;1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
6 changes: 6 additions & 0 deletions RaygunCore/RaygunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class RaygunOptions
/// </summary>
public bool IgnoreLocalErrors { get; set; }

/// <summary>
/// Gets or sets if <see cref="OperationCanceledException"/> is ignored in HTTP middleware.
/// Default <c>true</c>.
/// </summary>
public bool IgnoreCanceledErrors { get; set; } = true;

/// <summary>
/// Gets or sets if request headers are not logged.
/// Works only when Raygun HTTP services registered.
Expand Down
1 change: 1 addition & 0 deletions RaygunCore/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class RaygunServiceExtensions
/// </summary>
public static IRaygunBuilder AddRaygun(this IServiceCollection services)
{
services.AddOptions();
services.TryAddSingleton<IRaygunClient, DefaultRaygunClient>();
services.TryAddSingleton<IRaygunMessageBuilder, DefaultRaygunMessageBuilder>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IRaygunMessageProvider, MainMessageProvider>());
Expand Down

0 comments on commit 2f3a215

Please sign in to comment.