mirror of
https://github.com/Radarr/Radarr
synced 2025-03-11 06:33:16 +00:00
Fixed: (RadarrImport) Treat redirects as HTTP errors
This commit is contained in:
parent
4fe5e5974e
commit
9ed2553883
2 changed files with 46 additions and 23 deletions
|
@ -80,53 +80,63 @@ namespace NzbDrone.Core.ImportLists.Radarr
|
||||||
// Return early if there is not an API key
|
// Return early if there is not an API key
|
||||||
if (Settings.ApiKey.IsNullOrWhiteSpace())
|
if (Settings.ApiKey.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return new
|
return new { options = new List<object>() };
|
||||||
{
|
|
||||||
devices = new List<object>()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.Validate().Filter("ApiKey").ThrowOnError();
|
Settings.Validate().Filter("ApiKey").ThrowOnError();
|
||||||
|
|
||||||
if (action == "getProfiles")
|
if (action == "getProfiles")
|
||||||
{
|
{
|
||||||
var devices = _radarrV3Proxy.GetProfiles(Settings);
|
var profiles = _radarrV3Proxy.GetProfiles(Settings);
|
||||||
|
|
||||||
|
if (profiles == null)
|
||||||
|
{
|
||||||
|
return new { options = new List<object>() };
|
||||||
|
}
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
options = devices.OrderBy(d => d.Name, StringComparer.InvariantCultureIgnoreCase)
|
options = profiles.OrderBy(d => d.Name, StringComparer.InvariantCultureIgnoreCase)
|
||||||
.Select(d => new
|
.Select(d => new
|
||||||
{
|
{
|
||||||
Value = d.Id,
|
Value = d.Id,
|
||||||
Name = d.Name
|
Name = d.Name
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "getTags")
|
if (action == "getTags")
|
||||||
{
|
{
|
||||||
var devices = _radarrV3Proxy.GetTags(Settings);
|
var tags = _radarrV3Proxy.GetTags(Settings);
|
||||||
|
|
||||||
|
if (tags == null)
|
||||||
|
{
|
||||||
|
return new { options = new List<object>() };
|
||||||
|
}
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
options = devices.OrderBy(d => d.Label, StringComparer.InvariantCultureIgnoreCase)
|
options = tags.OrderBy(d => d.Label, StringComparer.InvariantCultureIgnoreCase)
|
||||||
.Select(d => new
|
.Select(d => new
|
||||||
{
|
{
|
||||||
Value = d.Id,
|
Value = d.Id,
|
||||||
Name = d.Label
|
Name = d.Label
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "getRootFolders")
|
if (action == "getRootFolders")
|
||||||
{
|
{
|
||||||
Settings.Validate().Filter("ApiKey").ThrowOnError();
|
var remoteRootFolders = _radarrV3Proxy.GetRootFolders(Settings);
|
||||||
|
|
||||||
var remoteRootfolders = _radarrV3Proxy.GetRootFolders(Settings);
|
if (remoteRootFolders == null)
|
||||||
|
{
|
||||||
|
return new { options = new List<object>() };
|
||||||
|
}
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
options = remoteRootfolders.OrderBy(d => d.Path, StringComparer.InvariantCultureIgnoreCase)
|
options = remoteRootFolders.OrderBy(d => d.Path, StringComparer.InvariantCultureIgnoreCase)
|
||||||
.Select(d => new
|
.Select(d => new
|
||||||
{
|
{
|
||||||
Value = d.Path,
|
Value = d.Path,
|
||||||
|
|
|
@ -63,6 +63,12 @@ namespace NzbDrone.Core.ImportLists.Radarr
|
||||||
return new ValidationFailure("ApiKey", "API Key is invalid");
|
return new ValidationFailure("ApiKey", "API Key is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ex.Response.HasHttpRedirect)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, "Radarr returned redirect and is invalid");
|
||||||
|
return new ValidationFailure("BaseUrl", "Radarr URL is invalid, are you missing a URL base?");
|
||||||
|
}
|
||||||
|
|
||||||
_logger.Error(ex, "Unable to connect to import list.");
|
_logger.Error(ex, "Unable to connect to import list.");
|
||||||
return new ValidationFailure(string.Empty, $"Unable to connect to import list: {ex.Message}. Check the log surrounding this error for details.");
|
return new ValidationFailure(string.Empty, $"Unable to connect to import list: {ex.Message}. Check the log surrounding this error for details.");
|
||||||
}
|
}
|
||||||
|
@ -84,11 +90,18 @@ namespace NzbDrone.Core.ImportLists.Radarr
|
||||||
|
|
||||||
var baseUrl = settings.BaseUrl.TrimEnd('/');
|
var baseUrl = settings.BaseUrl.TrimEnd('/');
|
||||||
|
|
||||||
var request = new HttpRequestBuilder(baseUrl).Resource(resource).Accept(HttpAccept.Json)
|
var request = new HttpRequestBuilder(baseUrl).Resource(resource)
|
||||||
.SetHeader("X-Api-Key", settings.ApiKey).Build();
|
.Accept(HttpAccept.Json)
|
||||||
|
.SetHeader("X-Api-Key", settings.ApiKey)
|
||||||
|
.Build();
|
||||||
|
|
||||||
var response = _httpClient.Get(request);
|
var response = _httpClient.Get(request);
|
||||||
|
|
||||||
|
if ((int)response.StatusCode > 299)
|
||||||
|
{
|
||||||
|
throw new HttpException(response);
|
||||||
|
}
|
||||||
|
|
||||||
var results = JsonConvert.DeserializeObject<List<TResource>>(response.Content);
|
var results = JsonConvert.DeserializeObject<List<TResource>>(response.Content);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
Loading…
Add table
Reference in a new issue