mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 05:13:18 -07:00
fix(notifications): Fixed the error when sending multiple test notifications. Added more logging when Discord complains the message is invalid
This commit is contained in:
parent
4013693c30
commit
fc14780bd3
2 changed files with 31 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
|||
using System.Net.Http;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Ombi.Api.Discord.Models;
|
||||
|
@ -23,7 +25,20 @@ namespace Ombi.Api.Discord
|
|||
|
||||
request.ApplicationJsonContentType();
|
||||
|
||||
await Api.Request(request);
|
||||
var response = await Api.Request(request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
throw new DiscordException(content, response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public class DiscordException : Exception
|
||||
{
|
||||
public DiscordException(string content, HttpStatusCode code) : base($"Exception when calling Discord with status code {code} and message: {content}")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,12 +110,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("discord")]
|
||||
public bool Discord([FromBody] DiscordNotificationSettings settings)
|
||||
public async Task<bool> Discord([FromBody] DiscordNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
DiscordNotification.NotifyAsync(
|
||||
await DiscordNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -133,13 +133,13 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("pushbullet")]
|
||||
public bool Pushbullet([FromBody] PushbulletSettings settings)
|
||||
public async Task<bool> Pushbullet([FromBody] PushbulletSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
settings.Enabled = true;
|
||||
PushbulletNotification.NotifyAsync(
|
||||
await PushbulletNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -157,12 +157,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("pushover")]
|
||||
public bool Pushover([FromBody] PushoverSettings settings)
|
||||
public async Task<bool> Pushover([FromBody] PushoverSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
PushoverNotification.NotifyAsync(
|
||||
await PushoverNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -181,12 +181,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("gotify")]
|
||||
public bool Gotify([FromBody] GotifySettings settings)
|
||||
public async Task<bool> Gotify([FromBody] GotifySettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
GotifyNotification.NotifyAsync(
|
||||
await GotifyNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -205,12 +205,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("webhook")]
|
||||
public bool Webhook([FromBody] WebhookSettings settings)
|
||||
public async Task<bool> Webhook([FromBody] WebhookSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
WebhookNotification.NotifyAsync(
|
||||
await WebhookNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -229,12 +229,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("mattermost")]
|
||||
public bool Mattermost([FromBody] MattermostNotificationSettings settings)
|
||||
public async Task<bool> Mattermost([FromBody] MattermostNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
MattermostNotification.NotifyAsync(
|
||||
await MattermostNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
@ -255,12 +255,12 @@ namespace Ombi.Controllers.V1.External
|
|||
/// <param name="settings">The settings.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("slack")]
|
||||
public bool Slack([FromBody] SlackNotificationSettings settings)
|
||||
public async Task<bool> Slack([FromBody] SlackNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
settings.Enabled = true;
|
||||
SlackNotification.NotifyAsync(
|
||||
await SlackNotification.NotifyAsync(
|
||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue