2
0
Add exception handling if host doesnt exist
This commit is contained in:
glax 2023-10-30 13:48:25 +01:00
parent 8caac538c9
commit 37266ea095

View File

@ -37,12 +37,19 @@ public class Kavita : LibraryConnector
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
};
HttpResponseMessage response = client.Send(requestMessage);
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
if (result is not null)
return result["token"]!.GetValue<string>();
else throw new Exception("Did not receive token.");
try
{
HttpResponseMessage response = client.Send(requestMessage);
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
if (result is not null)
return result["token"]!.GetValue<string>();
}
catch (HttpRequestException e)
{
Console.WriteLine($"Unable to retrieve token:\n\r{e}");
}
Console.WriteLine("Kavita: Did not receive token.");
throw new Exception("Kavita: Did not receive token.");
}
public override void UpdateLibrary()