|
19 | 19 | #endif
|
20 | 20 | using Microsoft.Azure.Commands.Common.Authentication.Models;
|
21 | 21 | using Microsoft.Azure.Commands.Common.Authentication.Properties;
|
| 22 | +using Microsoft.Azure.Commands.Common.Exceptions; |
22 | 23 | using System;
|
23 | 24 | using System.Collections.Concurrent;
|
24 | 25 | using System.Collections.Generic;
|
@@ -56,7 +57,7 @@ public virtual TClient CreateArmClient<TClient>(IAzureContext context, string en
|
56 | 57 | {
|
57 | 58 | if (context == null)
|
58 | 59 | {
|
59 |
| - throw new ApplicationException(Resources.NoSubscriptionInContext); |
| 60 | + throw new AzPSApplicationException(Resources.NoSubscriptionInContext, ErrorKind.UserError); |
60 | 61 | }
|
61 | 62 |
|
62 | 63 | var creds = AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, endpoint);
|
@@ -129,7 +130,7 @@ public virtual TClient CreateClient<TClient>(IAzureContext context, string endpo
|
129 | 130 | var exceptionMessage = endpoint == AzureEnvironment.Endpoint.ServiceManagement
|
130 | 131 | ? Resources.InvalidDefaultSubscription
|
131 | 132 | : Resources.NoSubscriptionInContext;
|
132 |
| - throw new ApplicationException(exceptionMessage); |
| 133 | + throw new AzPSApplicationException(exceptionMessage, ErrorKind.UserError); |
133 | 134 | }
|
134 | 135 |
|
135 | 136 | SubscriptionCloudCredentials creds = AzureSession.Instance.AuthenticationFactory.GetSubscriptionCloudCredentials(context, endpoint);
|
@@ -165,21 +166,21 @@ public virtual TClient CreateClient<TClient>(IAzureContextContainer profile, IAz
|
165 | 166 | {
|
166 | 167 | if (subscription == null)
|
167 | 168 | {
|
168 |
| - throw new ApplicationException(Resources.InvalidDefaultSubscription); |
| 169 | + throw new AzPSApplicationException(Resources.InvalidDefaultSubscription, ErrorKind.UserError); |
169 | 170 | }
|
170 | 171 |
|
171 | 172 | var account = profile.Accounts.FirstOrDefault((a) => string.Equals(a.Id, (subscription.GetAccount()), StringComparison.OrdinalIgnoreCase));
|
172 | 173 |
|
173 | 174 | if (null == account)
|
174 | 175 | {
|
175 |
| - throw new ArgumentException(string.Format("Account with name '{0}' does not exist.", subscription.GetAccount()), "accountName"); |
| 176 | + throw new AzPSArgumentException(string.Format("Account with name '{0}' does not exist.", subscription.GetAccount()), "accountName", ErrorKind.UserError); |
176 | 177 | }
|
177 | 178 |
|
178 | 179 | var environment = profile.Environments.FirstOrDefault((e) => string.Equals(e.Name, subscription.GetEnvironment(), StringComparison.OrdinalIgnoreCase));
|
179 | 180 |
|
180 | 181 | if (null == environment)
|
181 | 182 | {
|
182 |
| - throw new ArgumentException(string.Format(Resources.EnvironmentNotFound, subscription.GetEnvironment())); |
| 183 | + throw new AzPSArgumentException(string.Format(Resources.EnvironmentNotFound, subscription.GetEnvironment()), "environment", ErrorKind.UserError); |
183 | 184 | }
|
184 | 185 |
|
185 | 186 | AzureContext context = new AzureContext(subscription, account, environment);
|
|
0 commit comments