fixes, hopefully
This commit is contained in:
parent
7495e34ade
commit
cbc24e7672
13 changed files with 449 additions and 78 deletions
|
|
@ -47,9 +47,22 @@ public class ChatClientConnection : IDisposable
|
|||
var res = await _httpClient.GetAsync("/api/info");
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
// Auto-upgrade ServerUrl if redirected to HTTPS
|
||||
if (res.RequestMessage?.RequestUri != null &&
|
||||
res.RequestMessage.RequestUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) &&
|
||||
_state.ServerUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_state.ServerUrl = res.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority);
|
||||
_httpClient.BaseAddress = new Uri(_state.ServerUrl);
|
||||
}
|
||||
|
||||
var json = await res.Content.ReadAsStringAsync();
|
||||
return JsonSerializer.Deserialize<ServerInfoResponse>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
else
|
||||
{
|
||||
_state.SetStatus($"Server returned HTTP {(int)res.StatusCode} ({res.ReasonPhrase}) on /api/info");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -73,6 +86,15 @@ public class ChatClientConnection : IDisposable
|
|||
{
|
||||
var res = await _httpClient.PostAsync("/api/auth/register", content);
|
||||
var resJson = await res.Content.ReadAsStringAsync();
|
||||
if (string.IsNullOrWhiteSpace(resJson))
|
||||
{
|
||||
return new AuthResponse
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = $"Server returned HTTP {(int)res.StatusCode} ({res.ReasonPhrase}) with empty response."
|
||||
};
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<AuthResponse>(resJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })
|
||||
?? new AuthResponse { Success = false, ErrorMessage = "Invalid response from server." };
|
||||
}
|
||||
|
|
@ -97,6 +119,15 @@ public class ChatClientConnection : IDisposable
|
|||
{
|
||||
var res = await _httpClient.PostAsync("/api/auth/login", content);
|
||||
var resJson = await res.Content.ReadAsStringAsync();
|
||||
if (string.IsNullOrWhiteSpace(resJson))
|
||||
{
|
||||
return new AuthResponse
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = $"Server returned HTTP {(int)res.StatusCode} ({res.ReasonPhrase}) with empty response."
|
||||
};
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<AuthResponse>(resJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })
|
||||
?? new AuthResponse { Success = false, ErrorMessage = "Invalid response from server." };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue