Browse Source

Exception handling.

pull/681/head
Sebastian Stehle 5 years ago
parent
commit
2d1085d152
  1. 22
      backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs

22
backend/src/Squidex.Domain.Apps.Entities/History/NotifoService.cs

@ -20,6 +20,7 @@ using Squidex.Domain.Apps.Events.Contents;
using Squidex.Domain.Users; using Squidex.Domain.Users;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing;
using Squidex.Log;
using Squidex.Shared.Identity; using Squidex.Shared.Identity;
using Squidex.Shared.Users; using Squidex.Shared.Users;
@ -31,22 +32,28 @@ namespace Squidex.Domain.Apps.Entities.History
private readonly NotifoOptions options; private readonly NotifoOptions options;
private readonly IUrlGenerator urlGenerator; private readonly IUrlGenerator urlGenerator;
private readonly IUserResolver userResolver; private readonly IUserResolver userResolver;
private readonly ISemanticLog log;
private readonly IClock clock; private readonly IClock clock;
private readonly INotifoClient? client; private readonly INotifoClient? client;
public NotifoService(IOptions<NotifoOptions> options, IUrlGenerator urlGenerator, IUserResolver userResolver, IClock clock) public NotifoService(IOptions<NotifoOptions> options,
IUrlGenerator urlGenerator,
IUserResolver userResolver,
ISemanticLog log,
IClock clock)
{ {
Guard.NotNull(options, nameof(options)); Guard.NotNull(options, nameof(options));
Guard.NotNull(urlGenerator, nameof(urlGenerator)); Guard.NotNull(urlGenerator, nameof(urlGenerator));
Guard.NotNull(userResolver, nameof(userResolver)); Guard.NotNull(userResolver, nameof(userResolver));
Guard.NotNull(log, nameof(log));
Guard.NotNull(clock, nameof(clock)); Guard.NotNull(clock, nameof(clock));
this.options = options.Value; this.options = options.Value;
this.urlGenerator = urlGenerator; this.urlGenerator = urlGenerator;
this.userResolver = userResolver; this.userResolver = userResolver;
this.clock = clock; this.clock = clock;
this.log = log;
if (options.Value.IsConfigured()) if (options.Value.IsConfigured())
{ {
@ -86,6 +93,8 @@ namespace Squidex.Domain.Apps.Entities.History
return; return;
} }
try
{
var settings = new Dictionary<string, NotificationSettingDto> var settings = new Dictionary<string, NotificationSettingDto>
{ {
[Providers.WebPush] = new NotificationSettingDto [Providers.WebPush] = new NotificationSettingDto
@ -123,8 +132,17 @@ namespace Squidex.Domain.Apps.Entities.History
} }
}); });
var apiKey = response.First().ApiKey;
await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey, true); await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey, true);
} }
catch (Exception ex)
{
log.LogError(ex, w => w
.WriteProperty("action", "RegisterToNotifo")
.WriteProperty("status", "Failed"));
}
}
public async Task HandleEventsAsync(IEnumerable<(Envelope<AppEvent> AppEvent, HistoryEvent? HistoryEvent)> events) public async Task HandleEventsAsync(IEnumerable<(Envelope<AppEvent> AppEvent, HistoryEvent? HistoryEvent)> events)
{ {

Loading…
Cancel
Save