mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -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 System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Ombi.Api.Discord.Models;
|
using Ombi.Api.Discord.Models;
|
||||||
|
@ -23,7 +25,20 @@ namespace Ombi.Api.Discord
|
||||||
|
|
||||||
request.ApplicationJsonContentType();
|
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>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("discord")]
|
[HttpPost("discord")]
|
||||||
public bool Discord([FromBody] DiscordNotificationSettings settings)
|
public async Task<bool> Discord([FromBody] DiscordNotificationSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
DiscordNotification.NotifyAsync(
|
await DiscordNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -133,13 +133,13 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("pushbullet")]
|
[HttpPost("pushbullet")]
|
||||||
public bool Pushbullet([FromBody] PushbulletSettings settings)
|
public async Task<bool> Pushbullet([FromBody] PushbulletSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
PushbulletNotification.NotifyAsync(
|
await PushbulletNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -157,12 +157,12 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("pushover")]
|
[HttpPost("pushover")]
|
||||||
public bool Pushover([FromBody] PushoverSettings settings)
|
public async Task<bool> Pushover([FromBody] PushoverSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
PushoverNotification.NotifyAsync(
|
await PushoverNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -181,12 +181,12 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("gotify")]
|
[HttpPost("gotify")]
|
||||||
public bool Gotify([FromBody] GotifySettings settings)
|
public async Task<bool> Gotify([FromBody] GotifySettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
GotifyNotification.NotifyAsync(
|
await GotifyNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -205,12 +205,12 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("webhook")]
|
[HttpPost("webhook")]
|
||||||
public bool Webhook([FromBody] WebhookSettings settings)
|
public async Task<bool> Webhook([FromBody] WebhookSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
WebhookNotification.NotifyAsync(
|
await WebhookNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -229,12 +229,12 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("mattermost")]
|
[HttpPost("mattermost")]
|
||||||
public bool Mattermost([FromBody] MattermostNotificationSettings settings)
|
public async Task<bool> Mattermost([FromBody] MattermostNotificationSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
MattermostNotification.NotifyAsync(
|
await MattermostNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -255,12 +255,12 @@ namespace Ombi.Controllers.V1.External
|
||||||
/// <param name="settings">The settings.</param>
|
/// <param name="settings">The settings.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("slack")]
|
[HttpPost("slack")]
|
||||||
public bool Slack([FromBody] SlackNotificationSettings settings)
|
public async Task<bool> Slack([FromBody] SlackNotificationSettings settings)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
settings.Enabled = true;
|
settings.Enabled = true;
|
||||||
SlackNotification.NotifyAsync(
|
await SlackNotification.NotifyAsync(
|
||||||
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue