Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Exceptions;
using Microsoft.Identity.Client;
using Microsoft.Rest;

Expand Down Expand Up @@ -285,7 +286,7 @@ public ServiceClientCredentials GetServiceClientCredentials(IAzureContext contex
{
if (context.Account == null)
{
throw new ArgumentException(Resources.ArmAccountNotFound);
throw new AzPSArgumentException(Resources.ArmAccountNotFound, "context.Account", ErrorKind.UserError);
}
switch (context.Account.Type)
{
Expand Down
11 changes: 6 additions & 5 deletions src/Accounts/Authentication/Factories/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#endif
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Exceptions;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -56,7 +57,7 @@ public virtual TClient CreateArmClient<TClient>(IAzureContext context, string en
{
if (context == null)
{
throw new ApplicationException(Resources.NoSubscriptionInContext);
throw new AzPSApplicationException(Resources.NoSubscriptionInContext, ErrorKind.UserError);
}

var creds = AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, endpoint);
Expand Down Expand Up @@ -129,7 +130,7 @@ public virtual TClient CreateClient<TClient>(IAzureContext context, string endpo
var exceptionMessage = endpoint == AzureEnvironment.Endpoint.ServiceManagement
? Resources.InvalidDefaultSubscription
: Resources.NoSubscriptionInContext;
throw new ApplicationException(exceptionMessage);
throw new AzPSApplicationException(exceptionMessage, ErrorKind.UserError);
}

SubscriptionCloudCredentials creds = AzureSession.Instance.AuthenticationFactory.GetSubscriptionCloudCredentials(context, endpoint);
Expand Down Expand Up @@ -165,21 +166,21 @@ public virtual TClient CreateClient<TClient>(IAzureContextContainer profile, IAz
{
if (subscription == null)
{
throw new ApplicationException(Resources.InvalidDefaultSubscription);
throw new AzPSApplicationException(Resources.InvalidDefaultSubscription, ErrorKind.UserError);
}

var account = profile.Accounts.FirstOrDefault((a) => string.Equals(a.Id, (subscription.GetAccount()), StringComparison.OrdinalIgnoreCase));

if (null == account)
{
throw new ArgumentException(string.Format("Account with name '{0}' does not exist.", subscription.GetAccount()), "accountName");
throw new AzPSArgumentException(string.Format("Account with name '{0}' does not exist.", subscription.GetAccount()), "accountName", ErrorKind.UserError);
}

var environment = profile.Environments.FirstOrDefault((e) => string.Equals(e.Name, subscription.GetEnvironment(), StringComparison.OrdinalIgnoreCase));

if (null == environment)
{
throw new ArgumentException(string.Format(Resources.EnvironmentNotFound, subscription.GetEnvironment()));
throw new AzPSArgumentException(string.Format(Resources.EnvironmentNotFound, subscription.GetEnvironment()), "environment", ErrorKind.UserError);
}

AzureContext context = new AzureContext(subscription, account, environment);
Expand Down