diff --git a/source/Meadow.Core/MeadowCloudService.cs b/source/Meadow.Core/MeadowCloudService.cs index 93556f23..b54c8ff0 100644 --- a/source/Meadow.Core/MeadowCloudService.cs +++ b/source/Meadow.Core/MeadowCloudService.cs @@ -177,7 +177,14 @@ private async Task Send(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()) @@ -208,7 +215,7 @@ private async Task Send(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) @@ -217,6 +224,7 @@ private async Task Send(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; } @@ -276,7 +284,7 @@ private async Task Send(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"));