Skip to content

Commit

Permalink
feat(BackendApiService): use separateEndpoint for no token installati…
Browse files Browse the repository at this point in the history
…on info posts
  • Loading branch information
pkuehnel committed Jan 5, 2025
1 parent 05bb658 commit 9fda99f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions TeslaSolarCharger/Server/Services/BackendApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ public async Task PostInstallationInformation(string reason)
var tokenState = await tokenHelper.GetBackendTokenState(true);
var installationId = await tscConfigurationService.GetInstallationId().ConfigureAwait(false);
var currentVersion = await GetCurrentVersion().ConfigureAwait(false);
var url = configurationWrapper.BackendApiBaseUrl() + $"Client/NotifyInstallation?version={Uri.EscapeDataString(currentVersion ?? string.Empty)}&infoReason{Uri.EscapeDataString(reason)}";

using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(10);
if (tokenState == TokenState.UpToDate)
{
var url = configurationWrapper.BackendApiBaseUrl() + $"Client/NotifyInstallation?version={Uri.EscapeDataString(currentVersion ?? string.Empty)}&infoReason{Uri.EscapeDataString(reason)}";
var token = await teslaSolarChargerContext.BackendTokens.SingleAsync();
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Authorization = new("Bearer", token.AccessToken);
Expand All @@ -176,8 +177,8 @@ public async Task PostInstallationInformation(string reason)

logger.LogWarning("Error while sending installation information to backend. StatusCode: {statusCode}. Trying again without token", response.StatusCode);
}
url += $"&installationId={Uri.EscapeDataString(installationId.ToString())}";
var nonTokenRequest = new HttpRequestMessage(HttpMethod.Post, url);
var noTokenUrl = configurationWrapper.BackendApiBaseUrl() + $"Client/NotifyInstallationAnonymous?version={Uri.EscapeDataString(currentVersion ?? string.Empty)}&infoReason{Uri.EscapeDataString(reason)}&installationId={Uri.EscapeDataString(installationId.ToString())}";
var nonTokenRequest = new HttpRequestMessage(HttpMethod.Post, noTokenUrl);
var nonTokenResponse = await httpClient.SendAsync(nonTokenRequest).ConfigureAwait(false);
if (nonTokenResponse.IsSuccessStatusCode)
{
Expand Down
1 change: 0 additions & 1 deletion TeslaSolarCharger/Shared/Wrappers/ConfigurationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Configuration;
using TeslaSolarCharger.Shared.Contracts;
using TeslaSolarCharger.Shared.Dtos.BaseConfiguration;
using TeslaSolarCharger.Shared.Dtos.Contracts;
Expand Down

0 comments on commit 9fda99f

Please sign in to comment.