mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Improve error message handling (#497)
- Add special handling for token expired errors so they send with a clear flag that'll allow clients to take action on this case - Send error message instead of callstack for all messages, and ensure all resource manager paths send back inner exceptions so users can understand the true root cause.
This commit is contained in:
@@ -207,7 +207,7 @@ namespace Microsoft.SqlTools.ResourceProvider.DefaultImpl
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServiceFailedException(SR.AzureSubscriptionFailedErrorMessage, ex);
|
||||
throw new ServiceFailedException(SR.FailedToGetAzureSubscriptionsErrorMessage, ex);
|
||||
}
|
||||
}
|
||||
result = result ?? Enumerable.Empty<IAzureUserAccountSubscriptionContext>();
|
||||
@@ -234,38 +234,25 @@ namespace Microsoft.SqlTools.ResourceProvider.DefaultImpl
|
||||
|
||||
private async Task<IEnumerable<IAzureUserAccountSubscriptionContext>> GetSubscriptionFromServiceAsync(AzureUserAccount userAccount)
|
||||
{
|
||||
CommonUtil.CheckForNull(userAccount, nameof(userAccount));
|
||||
List<IAzureUserAccountSubscriptionContext> subscriptionList = new List<IAzureUserAccountSubscriptionContext>();
|
||||
|
||||
if (userAccount.NeedsReauthentication)
|
||||
{
|
||||
throw new ExpiredTokenException(SR.UserNeedsAuthenticationError);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (userAccount != null && !userAccount.NeedsReauthentication)
|
||||
{
|
||||
IAzureResourceManager resourceManager = ServiceProvider.GetService<IAzureResourceManager>();
|
||||
IEnumerable<IAzureUserAccountSubscriptionContext> contexts = await resourceManager.GetSubscriptionContextsAsync(userAccount);
|
||||
subscriptionList = contexts.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserNeedsAuthenticationException(SR.AzureSubscriptionFailedErrorMessage);
|
||||
}
|
||||
IAzureResourceManager resourceManager = ServiceProvider.GetService<IAzureResourceManager>();
|
||||
IEnumerable<IAzureUserAccountSubscriptionContext> contexts = await resourceManager.GetSubscriptionContextsAsync(userAccount);
|
||||
subscriptionList = contexts.ToList();
|
||||
}
|
||||
// TODO handle stale tokens
|
||||
//catch (MissingSecurityTokenException missingSecurityTokenException)
|
||||
//{
|
||||
// //User needs to reauthenticate
|
||||
// if (userAccount != null)
|
||||
// {
|
||||
// userAccount.NeedsReauthentication = true;
|
||||
// }
|
||||
// throw new UserNeedsAuthenticationException(SR.AzureSubscriptionFailedErrorMessage, missingSecurityTokenException);
|
||||
//}
|
||||
catch (ServiceExceptionBase)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServiceFailedException(SR.AzureSubscriptionFailedErrorMessage, ex);
|
||||
throw new ServiceFailedException(SR.FailedToGetAzureSubscriptionsErrorMessage, ex);
|
||||
}
|
||||
return subscriptionList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user