@@ -60,7 +60,7 @@ private set
60
60
{
61
61
if ( value )
62
62
{
63
- LastException = new Exception ( "The access key has expired." ) ;
63
+ LastException = null ;
64
64
}
65
65
_updateAt = DateTime . UtcNow ;
66
66
_isAuthorized = value ;
@@ -73,7 +73,7 @@ private set
73
73
74
74
public byte [ ] KeyBytes => _keyBytes ?? throw new ArgumentNullException ( nameof ( KeyBytes ) ) ;
75
75
76
- internal Exception LastException { get ; private set ; } = new Exception ( "The access key has not been initialized." ) ;
76
+ internal Exception ? LastException { get ; private set ; }
77
77
78
78
internal string GetAccessKeyUrl { get ; }
79
79
@@ -135,7 +135,7 @@ public async Task<string> GenerateAccessTokenAsync(string audience,
135
135
}
136
136
return Available
137
137
? AuthUtility . GenerateAccessToken ( KeyBytes , Kid , audience , claims , lifetime , algorithm )
138
- : throw new AzureSignalRAccessTokenNotAuthorizedException ( TokenCredential , GetExceptionMessage ( LastException ) , LastException ) ;
138
+ : throw new AzureSignalRAccessTokenNotAuthorizedException ( TokenCredential , GetExceptionMessage ( LastException , _keyBytes != null ) , LastException ) ;
139
139
}
140
140
141
141
internal void UpdateAccessKey ( string kid , string keyStr )
@@ -199,12 +199,12 @@ private async Task UpdateAccessKeyInternalAsync(TaskCompletionSource<bool> tcs)
199
199
tcs . TrySetResult ( false ) ;
200
200
}
201
201
202
- private static string GetExceptionMessage ( Exception exception )
202
+ private static string GetExceptionMessage ( Exception ? exception , bool initialized )
203
203
{
204
204
return exception switch
205
205
{
206
206
AzureSignalRUnauthorizedException => AzureSignalRUnauthorizedException . ErrorMessageMicrosoftEntra ,
207
- _ => exception . Message ,
207
+ _ => exception ? . Message ?? ( initialized ? "Access key has expired" : "The access key has not initialized" ) ,
208
208
} ;
209
209
}
210
210
0 commit comments