Bessere Fehlermeldung bei fehlgeschlagenem manuellem Login
This commit is contained in:
@@ -67,7 +67,19 @@ internal static class BaseFunc {
|
|||||||
// Senden der Anfrage und Abrufen der Antwort
|
// Senden der Anfrage und Abrufen der Antwort
|
||||||
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
||||||
if (!HttpResponseMessage.IsSuccessStatusCode)
|
if (!HttpResponseMessage.IsSuccessStatusCode)
|
||||||
throw new Exception("Fehler beim Einloggen " + HttpResponseMessage.Content);
|
{
|
||||||
|
//throw new Exception("Fehler beim Einloggen " + HttpResponseMessage.Content);
|
||||||
|
var byteArray = await HttpResponseMessage.Content.ReadAsByteArrayAsync();
|
||||||
|
string responseData = Encoding.UTF8.GetString(byteArray);
|
||||||
|
var options = new JsonDocumentOptions {
|
||||||
|
AllowTrailingCommas = true
|
||||||
|
};
|
||||||
|
using (JsonDocument doc = JsonDocument.Parse(responseData, options)) {
|
||||||
|
JsonElement root = doc.RootElement;
|
||||||
|
string message = root.GetProperty("message").GetString() ?? throw new Exception("Fehler: 'message' ist null.");
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Überprüfen, ob die Anfrage erfolgreich war
|
// Überprüfen, ob die Anfrage erfolgreich war
|
||||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user