Improved Webhook logging
This commit is contained in:
parent
0a05cb5de7
commit
61e31ec2e1
|
@ -13,7 +13,6 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
|
||||||
[HttpPost("mailtrap/{apiKey}")]
|
[HttpPost("mailtrap/{apiKey}")]
|
||||||
[Authorize("EmailApi", AuthenticationSchemes = "ApiKeyInRoute")]
|
[Authorize("EmailApi", AuthenticationSchemes = "ApiKeyInRoute")]
|
||||||
public async Task<IActionResult> Mailtrap(Webhook webhook, string apiKey) {
|
public async Task<IActionResult> Mailtrap(Webhook webhook, string apiKey) {
|
||||||
Console.WriteLine(apiKey);
|
|
||||||
foreach (var webhookEvent in webhook.Events) {
|
foreach (var webhookEvent in webhook.Events) {
|
||||||
var subscriber = await context.Set<EmailSubscriber>().FirstOrDefaultAsync(s => s.Email == webhookEvent.Email);
|
var subscriber = await context.Set<EmailSubscriber>().FirstOrDefaultAsync(s => s.Email == webhookEvent.Email);
|
||||||
|
|
||||||
|
@ -52,6 +51,9 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
|
||||||
subscriber.Unsubscribed = true;
|
subscriber.Unsubscribed = true;
|
||||||
subscriber.UnsubscribeReason ??= webhookEvent.Reason?.Humanize().Titleize() ?? "Rejected";
|
subscriber.UnsubscribeReason ??= webhookEvent.Reason?.Humanize().Titleize() ?? "Rejected";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
logger.LogInformation("Received unsupported event {EventType}. Skipping.", webhookEvent.Type);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
Loading…
Reference in a new issue