Skip to content

Commit

Permalink
#182 Catching exception from Webhook requests to prevent the containe…
Browse files Browse the repository at this point in the history
…r falling over.
  • Loading branch information
Dan Done committed Mar 22, 2023
1 parent b6fdadc commit 405eea3
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions SynoAI/Notifiers/Webhook/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 405eea3

Please sign in to comment.