Add exception handling if host doesnt exist
This commit is contained in:
parent
8caac538c9
commit
37266ea095
@ -37,12 +37,19 @@ public class Kavita : LibraryConnector
|
|||||||
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
||||||
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
||||||
};
|
};
|
||||||
|
try
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
{
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
if (result is not null)
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
||||||
return result["token"]!.GetValue<string>();
|
if (result is not null)
|
||||||
else throw new Exception("Did not receive token.");
|
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()
|
public override void UpdateLibrary()
|
||||||
|
Loading…
Reference in New Issue
Block a user