Add error handling to Notifiarr connect to reduce Sentry hits

Add Environment switch to Notifiarr connect
Add Instance Name to Notifiarr connect
pull/7140/head
nitsua 2 years ago committed by Qstick
parent 7ec0fd1cea
commit 8ae84222d1

@ -0,0 +1,8 @@
namespace NzbDrone.Core.Notifications.Notifiarr
{
public enum NotifiarrEnvironment
{
Live,
Development
}
}

@ -15,7 +15,6 @@ namespace NzbDrone.Core.Notifications.Notifiarr
public class NotifiarrProxy : INotifiarrProxy
{
private const string URL = "https://notifiarr.com/notifier.php";
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
@ -50,10 +49,19 @@ namespace NzbDrone.Core.Notifications.Notifiarr
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
switch ((int)ex.Response.StatusCode)
{
_logger.Error(ex, "API key is invalid: " + ex.Message);
return new ValidationFailure("APIKey", "API key is invalid");
case 401:
_logger.Error(ex, "API key is invalid: " + ex.Message);
return new ValidationFailure("APIKey", "API key is invalid");
case 400:
case 520:
case 521:
case 522:
case 523:
case 524:
_logger.Error(ex, "Unable to send test notification: " + ex.Message);
return new ValidationFailure("", "Unable to send test notification");
}
_logger.Error(ex, "Unable to send test message: " + ex.Message);
@ -70,8 +78,10 @@ namespace NzbDrone.Core.Notifications.Notifiarr
{
try
{
var requestBuilder = new HttpRequestBuilder(URL).Post();
var url = settings.Environment == (int)NotifiarrEnvironment.Development ? "https://dev.notifiarr.com" : "https://notifiarr.com";
var requestBuilder = new HttpRequestBuilder(url + "/notifier.php").Post();
requestBuilder.AddFormParameter("api", settings.APIKey).Build();
requestBuilder.AddFormParameter("instanceName", settings.InstanceName).Build();
foreach (string key in message.Keys)
{
@ -84,10 +94,19 @@ namespace NzbDrone.Core.Notifications.Notifiarr
}
catch (HttpException ex)
{
if (ex.Response.StatusCode == HttpStatusCode.BadRequest)
switch ((int)ex.Response.StatusCode)
{
_logger.Error(ex, "API key is invalid");
throw;
case 401:
_logger.Error(ex, "API key is invalid");
throw;
case 400:
case 520:
case 521:
case 522:
case 523:
case 524:
_logger.Error(ex, "Unable to send notification");
throw;
}
throw new NotifiarrException("Unable to send notification", ex);

@ -19,6 +19,10 @@ namespace NzbDrone.Core.Notifications.Notifiarr
[FieldDefinition(0, Label = "API Key", Privacy = PrivacyLevel.ApiKey, HelpText = "Your API key from your profile", HelpLink = "https://notifiarr.com")]
public string APIKey { get; set; }
[FieldDefinition(1, Label = "Instance Name", Advanced = true, HelpText = "Unique name for this instance", HelpLink = "https://notifiarr.com")]
public string InstanceName { get; set; }
[FieldDefinition(2, Label = "Environment", Advanced = true, Type = FieldType.Select, SelectOptions = typeof(NotifiarrEnvironment), HelpText = "Live unless told otherwise", HelpLink = "https://notifiarr.com")]
public int Environment { get; set; }
public NzbDroneValidationResult Validate()
{

Loading…
Cancel
Save