mirror of
https://github.com/C9Glax/tranga.git
synced 2025-01-12 11:27:32 +01:00
Throw more readable exceptions if deserialization fails for Mangaconnectors.
#249
This commit is contained in:
parent
895128a462
commit
96f3dbce65
@ -1,4 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Tranga.MangaConnectors;
|
namespace Tranga.MangaConnectors;
|
||||||
@ -22,29 +24,22 @@ public class MangaConnectorJsonConverter : JsonConverter
|
|||||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
JObject jo = JObject.Load(reader);
|
JObject jo = JObject.Load(reader);
|
||||||
switch (jo.GetValue("name")!.Value<string>()!)
|
string? connectorName = jo.Value<string>("name");
|
||||||
|
if (connectorName is null)
|
||||||
|
throw new ConstraintException("Name can not be null.");
|
||||||
|
return connectorName switch
|
||||||
{
|
{
|
||||||
case "MangaDex":
|
"MangaDex" => this._connectors.First(c => c is MangaDex),
|
||||||
return this._connectors.First(c => c is MangaDex);
|
"Manganato" => this._connectors.First(c => c is Manganato),
|
||||||
case "Manganato":
|
"MangaKatana" => this._connectors.First(c => c is MangaKatana),
|
||||||
return this._connectors.First(c => c is Manganato);
|
"Mangasee" => this._connectors.First(c => c is Mangasee),
|
||||||
case "MangaKatana":
|
"Mangaworld" => this._connectors.First(c => c is Mangaworld),
|
||||||
return this._connectors.First(c => c is MangaKatana);
|
"Bato" => this._connectors.First(c => c is Bato),
|
||||||
case "Mangasee":
|
"Manga4Life" => this._connectors.First(c => c is MangaLife),
|
||||||
return this._connectors.First(c => c is Mangasee);
|
"ManhuaPlus" => this._connectors.First(c => c is ManhuaPlus),
|
||||||
case "Mangaworld":
|
"MangaHere" => this._connectors.First(c => c is MangaHere),
|
||||||
return this._connectors.First(c => c is Mangaworld);
|
_ => throw new UnreachableException($"Could not find Connector with name {connectorName}")
|
||||||
case "Bato":
|
};
|
||||||
return this._connectors.First(c => c is Bato);
|
|
||||||
case "Manga4Life":
|
|
||||||
return this._connectors.First(c => c is MangaLife);
|
|
||||||
case "ManhuaPlus":
|
|
||||||
return this._connectors.First(c => c is ManhuaPlus);
|
|
||||||
case "MangaHere":
|
|
||||||
return this._connectors.First(c => c is MangaHere);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanWrite => false;
|
public override bool CanWrite => false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user