Skip to content

Commit

Permalink
Issue crc-org#128 Show error notification if correct pull-secret form…
Browse files Browse the repository at this point in the history
…at is not used

earlier it was showing a notification as stored even if daemon returned an error
  • Loading branch information
anjannath committed Sep 3, 2021
1 parent 482f4da commit 1f0ec54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
12 changes: 8 additions & 4 deletions CRCTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,14 @@ async private void StartMenu_Click(object sender, EventArgs e)

TaskHelpers.TryTask(Tasks.SendTelemetry, Actions.EnterPullSecret).NoAwait();

await TaskHelpers.TryTaskAndNotify(Tasks.SetPullSecret, pullSecretContent,
"Pull Secret stored",
"Pull Secret not stored",
String.Empty);
// Store pullsecret; returns false is not able to
var stored = await TaskHelpers.TryTask(Tasks.SetPullSecret, pullSecretContent);
if(!stored)
{
TrayIcon.NotifyError(@"Pull-secret not stored. Please check if valid format is used.");
return;
}

}

TrayIcon.NotifyInfo(@"Starting Cluster");
Expand Down
31 changes: 27 additions & 4 deletions Communication/DaemonCommander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static class DaemonCommander

private static T getResultsForBasicCommand<T>(string command, int timeout = 20)
{
var output = SendBasicCommand(command, timeout);
var output = BasicGetCommand(command, timeout);

var options = new JsonSerializerOptions
{
Expand Down Expand Up @@ -110,8 +110,26 @@ public static bool GetPullSecret()

public static bool SetPullSecret(string data)
{
var result = sendPostRequest(BasicCommands.PullSecret, data, 30);
return true;
try
{
_ = BasicPostCommand(BasicCommands.PullSecret, data, 30);
return true;
}
catch (AggregateException ae)
{
ae.Handle((x) =>
{
if (x is APIException) // This we know how to handle.
{
// Marking as handled
return true;
}

return false;
});

return false;
}
}

public static void PostTelemetryRecord(string action)
Expand All @@ -124,11 +142,16 @@ public static void PostTelemetryRecord(string action)
_ = sendPostRequest(BasicCommands.Telemetry, JsonSerializer.Serialize(tr), 30);
}

private static string SendBasicCommand(string command, int timeout)
private static string BasicGetCommand(string command, int timeout)
{
return sendGetRequest(command, timeout).Result;
}

private static string BasicPostCommand(string command, string content, int timeout)
{
return sendPostRequest(command, content, timeout).Result;
}

private static async Task<string> sendGetRequest(string command, int timeout)
{
return await sendRequest(prepareRequest(HttpMethod.Get,
Expand Down

0 comments on commit 1f0ec54

Please sign in to comment.