From 405eea3296c8f0dadb8e761659e7f6abebb6cc4b Mon Sep 17 00:00:00 2001 From: Dan Done Date: Wed, 22 Mar 2023 10:37:54 +0000 Subject: [PATCH] #182 Catching exception from Webhook requests to prevent the container falling over. --- SynoAI/Notifiers/Webhook/Webhook.cs | 46 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/SynoAI/Notifiers/Webhook/Webhook.cs b/SynoAI/Notifiers/Webhook/Webhook.cs index 403fb1f..f83a6a6 100644 --- a/SynoAI/Notifiers/Webhook/Webhook.cs +++ b/SynoAI/Notifiers/Webhook/Webhook.cs @@ -118,26 +118,34 @@ public override async Task SendAsync(Camera camera, Notification notification, I logger.LogInformation($"{camera.Name}: Webhook: Calling {Method}."); HttpResponseMessage response; - switch (Method) + try { - case "DELETE": - response = await client.DeleteAsync(Url); - break; - case "GET": - response = await client.GetAsync(Url); - break; - case "PATCH": - response = await client.PatchAsync(Url, content); - break; - case "POST": - response = await client.PostAsync(Url, content); - break; - case "PUT": - response = await client.PutAsync(Url, content); - break; - default: - logger.LogError($"{camera.Name}: Webhook: The method type '{Method}' is not supported."); - return; + switch (Method) + { + case "DELETE": + response = await client.DeleteAsync(Url); + break; + case "GET": + response = await client.GetAsync(Url); + break; + case "PATCH": + response = await client.PatchAsync(Url, content); + break; + case "POST": + response = await client.PostAsync(Url, content); + break; + case "PUT": + response = await client.PutAsync(Url, content); + break; + default: + logger.LogError($"{camera.Name}: Webhook: The method type '{Method}' is not supported."); + return; + } + } + catch (Exception ex) + { + logger.LogError($"{camera.Name}: Webhook: Unhandled Exception occurred '{ex.Message}'."); + return; } if (response.IsSuccessStatusCode)