Skip to content

Commit

Permalink
Fixed: (AvistaZ) Improve message for failed logins
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Dec 2, 2023
1 parent dcfdd49 commit 7c38ec2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs
Expand Up @@ -7,6 +7,7 @@
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Messaging.Events;

namespace NzbDrone.Core.Indexers.Definitions.Avistaz
Expand Down Expand Up @@ -54,14 +55,24 @@ public override IParseIndexerResponse GetParser()

protected override async Task DoLogin()
{
Settings.Token = await GetToken();

if (Definition.Id > 0)
try
{
_indexerRepository.UpdateSettings((IndexerDefinition)Definition);
Settings.Token = await GetToken();

if (Definition.Id > 0)
{
_indexerRepository.UpdateSettings((IndexerDefinition)Definition);
}

_logger.Debug("Avistaz authentication succeeded.");
}
catch (HttpException ex) when (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
{
_logger.Warn(ex, "Failed to authenticate with Avistaz");

_logger.Debug("Avistaz authentication succeeded.");
var jsonResponse = STJson.Deserialize<AvistazErrorResponse>(ex.Response.Content);
throw new IndexerAuthException(jsonResponse?.Message ?? "Unauthorized request to indexer");
}
}

protected override bool CheckIfLoginNeeded(HttpResponse httpResponse)
Expand Down

0 comments on commit 7c38ec2

Please sign in to comment.