diff --git a/WebhookRelayService/Controllers/WebhookController.cs b/WebhookRelayService/Controllers/WebhookController.cs index 9700463..a310024 100644 --- a/WebhookRelayService/Controllers/WebhookController.cs +++ b/WebhookRelayService/Controllers/WebhookController.cs @@ -56,6 +56,9 @@ public async Task Webhook() return Ok(); } catch (Exception ex) { + if (ex is UnauthorizedAccessException) { + return Unauthorized(); + } _logger.LogError("Webhook error", ex); SentrySdk.CaptureException(ex); return StatusCode(500); diff --git a/WebhookRelayService/Services/WebhookService.cs b/WebhookRelayService/Services/WebhookService.cs index 0fa43ec..b1dba63 100644 --- a/WebhookRelayService/Services/WebhookService.cs +++ b/WebhookRelayService/Services/WebhookService.cs @@ -30,32 +30,24 @@ public WebhookService(IWebhookUserRepository webhookUserRepository, Settings set public async Task HandleWebhook(int webhookId, Webhook webhook, string payload, string signature) { - try + var user = await _webhookUserRepository.GetByWebhookId(webhookId); + if (user == null) { - var user = await _webhookUserRepository.GetByWebhookId(webhookId); - if (user == null) - { - return "gone"; - } - - if (!_settings.SkipSignatureCheck) - await ValidateSignature(user.WebhookSecret, payload, signature); - else - _logger.LogInformation("Skipped signature check"); + return "gone"; + } - if (_settings.Logging) - { - _logger.LogInformation($"Notification {webhook.GetNotificationJson()}"); - } + if (!_settings.SkipSignatureCheck) + await ValidateSignature(user.WebhookSecret, payload, signature); + else + _logger.LogInformation("Skipped signature check"); - await PushNotificationAndHandleResult(user, webhook.GetNotificationJson()); - return "ok"; - } - catch (Exception ex) + if (_settings.Logging) { - SentrySdk.CaptureException(ex); - return "error"; + _logger.LogInformation($"Notification {webhook.GetNotificationJson()}"); } + + await PushNotificationAndHandleResult(user, webhook.GetNotificationJson()); + return "ok"; } public async Task PushNotificationAndHandleResult(WebhookUser user, string content) @@ -106,10 +98,7 @@ private async Task ValidateSignature(string secret, string payload, string signa _logger.LogError($"Secret: {secret}"); _logger.LogError($"Payload: {payload}"); } - else - { - throw new UnauthorizedAccessException(); - } + throw new UnauthorizedAccessException(); } } }