Skip to content

Commit

Permalink
Fixed: (AvistaZ) Avoid parsing invalid JSON on auth
Browse files Browse the repository at this point in the history
Closes #2030
  • Loading branch information
mynameisbogdan committed Feb 16, 2024
1 parent 858f161 commit 5d35f1d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs
Expand Up @@ -70,7 +70,7 @@ protected override async Task DoLogin()
{
_logger.Warn(ex, "Failed to authenticate with Avistaz");

var jsonResponse = STJson.Deserialize<AvistazErrorResponse>(ex.Response.Content);
STJson.TryDeserialize<AvistazErrorResponse>(ex.Response.Content, out var jsonResponse);
throw new IndexerAuthException(jsonResponse?.Message ?? "Unauthorized request to indexer");
}
}
Expand Down Expand Up @@ -98,8 +98,8 @@ protected override async Task<ValidationFailure> TestConnection()
{
_logger.Warn(ex, "Unauthorized request to indexer");

var jsonResponse = new HttpResponse<AvistazErrorResponse>(ex.Response);
return new ValidationFailure(string.Empty, jsonResponse.Resource?.Message ?? "Unauthorized request to indexer");
STJson.TryDeserialize<AvistazErrorResponse>(ex.Response.Content, out var jsonResponse);
return new ValidationFailure(string.Empty, jsonResponse?.Message ?? "Unauthorized request to indexer");
}

_logger.Warn(ex, "Unable to connect to indexer");
Expand Down Expand Up @@ -134,7 +134,10 @@ private async Task<string> GetToken()

var response = await ExecuteAuth(authLoginRequest);

var authResponse = STJson.Deserialize<AvistazAuthResponse>(response.Content);
if (!STJson.TryDeserialize<AvistazAuthResponse>(response.Content, out var authResponse))
{
throw new Exception("Invalid response from AvistaZ, the response is not valid JSON");
}

return authResponse.Token;
}
Expand Down

0 comments on commit 5d35f1d

Please sign in to comment.