Skip to content

Commit

Permalink
Merge pull request #413 from WildernessLabs/bug/cloud-send
Browse files Browse the repository at this point in the history
check result of Auth on Send
  • Loading branch information
ctacke authored Dec 14, 2023
2 parents ed67931 + 83bb0ea commit 53175af
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions source/Meadow.Core/MeadowCloudService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ private async Task<bool> Send<T>(T item, string endpoint)

if (CurrentJwt == null)
{
await Authenticate();
if (!await Authenticate())
{
errorMessage = $"Cloud auth failed before sending";
ServiceError?.Invoke(this, errorMessage);
Resolver.Log.Warn(errorMessage);
// TODO: should we retry after this?
return false;
}
}

using (HttpClient client = new HttpClient())
Expand Down Expand Up @@ -208,7 +215,7 @@ private async Task<bool> Send<T>(T item, string endpoint)

if (response.IsSuccessStatusCode)
{
Resolver.Log.Debug("cloud log success");
Resolver.Log.Debug("cloud send success");
result = true;
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
Expand All @@ -217,6 +224,7 @@ private async Task<bool> Send<T>(T item, string endpoint)
{
attempt++;
Resolver.Log.Debug($"Unauthorized, re-authenticating");
// by setting this to null and retrying, Authenticate will get called
CurrentJwt = null;
goto retry;
}
Expand Down Expand Up @@ -276,7 +284,7 @@ private async Task<bool> Send<T>(T item, string endpoint)
return pkFileContent;
}
}
else if(SRI.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
else if (SRI.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var sshFolder = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh"));

Expand Down

0 comments on commit 53175af

Please sign in to comment.