Skip to content

Commit 4876f1e

Browse files
bug: error handling to clean up the logs
1 parent 19414fe commit 4876f1e

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/TwitchStreamingTools/Services/TwitchAccountService.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public TwitchAccountService(ITwitchClientProxy twitchClient, IConfiguration conf
5858

5959
/// <inheritdoc />
6060
public async Task UpdateCredentials(string bearer, string refresh, DateTime expires) {
61+
var oauth = new TwitchAccessToken {
62+
AccessToken = bearer,
63+
RefreshToken = refresh,
64+
ExpiresUtc = expires
65+
};
66+
6167
var twitchApi = new TwitchApiWrapper {
62-
OAuth = new TwitchAccessToken {
63-
AccessToken = bearer,
64-
RefreshToken = refresh,
65-
ExpiresUtc = expires
66-
}
68+
OAuth = oauth
6769
};
6870

6971
(string? id, string? username)? user = null;
@@ -74,18 +76,14 @@ public async Task UpdateCredentials(string bearer, string refresh, DateTime expi
7476
// Do nothing
7577
}
7678

77-
_configuration.OAuth = new TwitchAccessToken {
78-
AccessToken = bearer,
79-
RefreshToken = refresh,
80-
ExpiresUtc = expires
81-
};
79+
_configuration.OAuth = oauth;
8280

8381
_configuration.TwitchUsername = user?.username;
8482
_configuration.WriteConfiguration();
8583
_twitchClient.TwitchOAuthToken = bearer;
8684
_twitchClient.TwitchUsername = user?.username;
8785

88-
OnCredentialsChanged?.Invoke(null);
86+
OnCredentialsChanged?.Invoke(oauth);
8987
await OnCheckCredentials();
9088
}
9189

@@ -108,10 +106,10 @@ public void DeleteCredentials() {
108106
/// </summary>
109107
private async Task OnCheckCredentials() {
110108
_timer.Stop();
109+
// Grab the value so we can check if the value changed
110+
bool credsWereValid = CredentialsAreValid;
111+
111112
try {
112-
// Grab the value so we can check if the value changed
113-
bool previousValue = CredentialsAreValid;
114-
115113
// Refresh the token
116114
await DoTokenRefreshIfNearExpiration();
117115

@@ -122,16 +120,18 @@ private async Task OnCheckCredentials() {
122120
// Update the credentials
123121
CredentialsAreValid = !string.IsNullOrWhiteSpace(username);
124122
TwitchUsername = username;
125-
126-
// Fire off the event if something changed
127-
if (previousValue != CredentialsAreValid) {
128-
OnCredentialsStatusChanged?.Invoke(CredentialsAreValid);
129-
}
130123
}
131124
catch {
132-
// Do nothing
125+
if (credsWereValid) {
126+
DeleteCredentials();
127+
}
133128
}
134129
finally {
130+
// Fire off the event if something changed
131+
if (credsWereValid != CredentialsAreValid) {
132+
OnCredentialsStatusChanged?.Invoke(CredentialsAreValid);
133+
}
134+
135135
_timer.Start();
136136
}
137137
}

src/TwitchStreamingTools/ViewModels/Pages/SettingsView/TtsSkipUsernamesViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ private void TtsSkipped_OnCollectionChanged(object? sender, NotifyCollectionChan
136136
private async void UserListRefreshTimer_OnElapsed(object sender, ElapsedEventArgs e) {
137137
try {
138138
var api = new TwitchApiWrapper();
139+
if (string.IsNullOrWhiteSpace(api.OAuth?.AccessToken)) {
140+
return;
141+
}
139142

140143
(string? id, string? username) loggedInUser = await api.GetUser().ConfigureAwait(false);
141144

0 commit comments

Comments
 (0)