Fixed: Fingerprinting service swallows UnexpectedHtmlContentException (#808)

pull/6/head
ta264 6 years ago committed by GitHub
parent d381bab9d9
commit adfaec3864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,11 @@ using System.IO;
using System.Linq;
using NzbDrone.Core.Parser.Model;
using System;
using NzbDrone.Common.Http;
using Moq;
using static NzbDrone.Core.Parser.FingerprintingService;
using NzbDrone.Test.Common;
using System.Net;
namespace NzbDrone.Core.Test.ParserTests
{
@ -181,5 +186,19 @@ FINGERPRINT=AQAHJlMURlEURcgP6cwRD43Y4Ptw9FowncWPWkf6GB9-JYdP9OgJHw8u4Apw4SsOHMdx
idpairs[1].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
idpairs[2].Item1.AcoustIdResults.Should().BeNull();
}
[Test]
public void should_not_throw_if_api_returns_html()
{
Mocker.GetMock<IHttpClient>().Setup(x => x.Post<LookupResponse>(It.IsAny<HttpRequest>()))
.Callback<HttpRequest>(req => throw new UnexpectedHtmlContentException(new HttpResponse(req, req.Headers, "html content", HttpStatusCode.Accepted)));
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "nin.mp3");
var localTrack = new LocalTrack { Path = path };
Subject.Lookup(new List<LocalTrack> { localTrack }, 0.5);
localTrack.AcoustIdResults.Should().BeNull();
ExceptionVerification.ExpectedWarns(1);
}
}
}

@ -360,7 +360,18 @@ namespace NzbDrone.Core.Parser
httpRequest.Headers.ContentType = "application/x-www-form-urlencoded";
httpRequest.SuppressHttpError = true;
var httpResponse = _httpClient.Post<LookupResponse>(httpRequest);
HttpResponse<LookupResponse> httpResponse;
try
{
httpResponse = _httpClient.Post<LookupResponse>(httpRequest);
}
catch (UnexpectedHtmlContentException e)
{
_logger.Warn(e, "AcoustId API gave invalid response");
return;
}
var response = httpResponse.Resource;
// The API will give errors if fingerprint isn't found or is invalid.
@ -407,33 +418,33 @@ namespace NzbDrone.Core.Parser
_logger.Debug($"*** FingerprintingService TestCaseGenerator ***\n{JsonConvert.SerializeObject(output, SerializerSettings)}");
}
private class LookupResponse
public class LookupResponse
{
public string Status { get; set; }
public LookupError Error { get; set; }
public List<LookupResultListItem> Fingerprints { get; set; }
}
private class LookupError
public class LookupError
{
public string Message { get; set; }
public int Code { get; set; }
}
private class LookupResultListItem
public class LookupResultListItem
{
public int index { get; set; }
public List<LookupResult> Results { get; set; }
}
private class LookupResult
public class LookupResult
{
public string Id { get; set; }
public double Score { get; set; }
public List<RecordingResult> Recordings { get; set; }
}
private class RecordingResult
public class RecordingResult
{
public string Id { get; set; }
}

Loading…
Cancel
Save