Skip to content

Commit e6131e5

Browse files
authored
Merge pull request #77 from Owaan/fix-error-on-test-api-token
Ensure profileId is set when testing API token
2 parents 4aa40bd + 8d5b00c commit e6131e5

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

TarkovMonitor/MainBlazorUI.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ public MainBlazorUI()
7474
{
7575
if (Properties.Settings.Default.tarkovTrackerToken != "")
7676
{
77-
TarkovTracker.SetToken(e.Profile.Id, Properties.Settings.Default.tarkovTrackerToken);
77+
try {
78+
TarkovTracker.SetToken(e.Profile.Id, Properties.Settings.Default.tarkovTrackerToken);
79+
} catch (Exception ex) {
80+
messageLog.AddMessage($"Error setting token from previously saved settings {ex.Message}", "exception");
81+
}
82+
7883
Properties.Settings.Default.tarkovTrackerToken = "";
7984
Properties.Settings.Default.Save();
8085
}
@@ -460,20 +465,20 @@ private async Task UpdateHideoutStations()
460465

461466
private async Task InitializeProgress()
462467
{
463-
if (TarkovTracker.GetToken(eft.CurrentProfile.Id) == "")
464-
{
465-
messageLog.AddMessage("To automatically track task progress, set your Tarkov Tracker token in Settings");
466-
return;
467-
}
468-
messageLog.AddMessage($"Using {eft.CurrentProfile.Type} profile");
469468
try
470469
{
471470
await TarkovTracker.SetProfile(eft.CurrentProfile.Id);
472-
return;
473471
}
474472
catch (Exception ex)
475473
{
476-
messageLog.AddMessage($"Error getting Tarkov Tracker progress: {ex.Message}");
474+
messageLog.AddMessage($"Profile does not exist: {ex.Message}");
475+
return;
476+
}
477+
messageLog.AddMessage($"Using {eft.CurrentProfile.Type} profile");
478+
if (TarkovTracker.GetToken(eft.CurrentProfile.Id) == "")
479+
{
480+
messageLog.AddMessage("To automatically track task progress, set your Tarkov Tracker token in Settings");
481+
return;
477482
}
478483
try
479484
{
@@ -486,6 +491,7 @@ private async Task InitializeProgress()
486491
catch (Exception ex)
487492
{
488493
messageLog.AddMessage($"Error updating progress: {ex.Message}");
494+
return;
489495
}
490496
}
491497

TarkovMonitor/TarkovTracker.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal interface ITarkovTrackerAPI
3535
{
3636
AuthorizationHeaderValueGetter = (rq, cr) => {
3737
return Task.Run<string>(() => {
38-
return tokens[currentProfile];
38+
return GetToken(currentProfile);
3939
});
4040
},
4141
}
@@ -68,7 +68,7 @@ public static void SetToken(string profileId, string token)
6868
{
6969
if (profileId == "")
7070
{
71-
return;
71+
throw new Exception("No PVP or PVE profile initialised, please launch Escape from Tarkov first");
7272
}
7373
tokens[profileId] = token;
7474
Properties.Settings.Default.tarkovTrackerTokens = JsonSerializer.Serialize(tokens);
@@ -77,6 +77,10 @@ public static void SetToken(string profileId, string token)
7777

7878
public static async Task<ProgressResponse> SetProfile(string profileId)
7979
{
80+
if (profileId == "") {
81+
throw new Exception("Can't set PVP or PVE profile, please launch Escape from Tarkov and then restart this application");
82+
}
83+
8084
if (currentProfile == profileId)
8185
{
8286
return Progress;

0 commit comments

Comments
 (0)