mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-17 10:45:49 +02:00
Error handling in migration to new quality
This commit is contained in:
parent
fe4f3d5d1e
commit
c9a77e99a0
@ -41,15 +41,22 @@ public static object Deserialize(string json, Type type)
|
||||
return JsonConvert.DeserializeObject(json, type, SerializerSetting);
|
||||
}
|
||||
|
||||
public static T TryDeserialize<T>(string json) where T : new()
|
||||
public static bool TryDeserialize<T>(string json, out T result) where T : new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Deserialize<T>(json);
|
||||
result = Deserialize<T>(json);
|
||||
return true;
|
||||
}
|
||||
catch (JsonReaderException ex)
|
||||
{
|
||||
return default(T);
|
||||
result = default(T);
|
||||
return false;
|
||||
}
|
||||
catch (JsonSerializationException ex)
|
||||
{
|
||||
result = default(T);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,12 @@ public class update_with_quality_converters : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("QualityProfiles").AddColumn("Items").AsString().Nullable();
|
||||
if (!Schema.Table("QualityProfiles").Column("Items").Exists())
|
||||
{
|
||||
Alter.Table("QualityProfiles").AddColumn("Items").AsString().Nullable();
|
||||
}
|
||||
|
||||
Execute.WithConnection(ConvertQualityProfiles);
|
||||
|
||||
Execute.WithConnection(ConvertQualityModels);
|
||||
}
|
||||
|
||||
@ -80,7 +82,12 @@ private void ConvertQualityModel(IDbConnection conn, IDbTransaction tran, string
|
||||
var id = qualityModelReader.GetInt32(0);
|
||||
var qualityJson = qualityModelReader.GetString(1);
|
||||
|
||||
var quality = Json.Deserialize<QualityModel>(qualityJson);
|
||||
QualityModel quality;
|
||||
|
||||
if (!Json.TryDeserialize<QualityModel>(qualityJson, out quality))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var qualityNewJson = qualityModelConverter.ToDB(quality);
|
||||
|
||||
|
@ -31,10 +31,10 @@ public SabAddResponse DownloadNzb(Stream nzb, string title, string category, int
|
||||
var action = String.Format("mode=addfile&cat={0}&priority={1}", category, priority);
|
||||
|
||||
request.AddFile("name", ReadFully(nzb), title, "application/x-nzb");
|
||||
|
||||
var response = Json.TryDeserialize<SabAddResponse>(ProcessRequest(request, action));
|
||||
|
||||
if (response == null)
|
||||
SabAddResponse response;
|
||||
|
||||
if (!Json.TryDeserialize<SabAddResponse>(ProcessRequest(request, action), out response))
|
||||
{
|
||||
response = new SabAddResponse();
|
||||
response.Status = true;
|
||||
@ -87,9 +87,9 @@ private void CheckForError(IRestResponse response)
|
||||
throw new ApplicationException("Unable to connect to SABnzbd, please check your settings");
|
||||
}
|
||||
|
||||
var result = Json.TryDeserialize<SabJsonError>(response.Content);
|
||||
SabJsonError result;
|
||||
|
||||
if (result == null)
|
||||
if (!Json.TryDeserialize<SabJsonError>(response.Content, out result))
|
||||
{
|
||||
//Handle plain text responses from SAB
|
||||
result = new SabJsonError();
|
||||
|
Loading…
Reference in New Issue
Block a user