Skip to content

Commit bce12b7

Browse files
author
Bram Verswalm
committed
Avoid obfuscated aggregated exceptions by returning the innerexception message
1 parent 5c9ff4a commit bce12b7

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

OrbitOne.BuildScreen/OrbitOne.BuildScreen.Configuration/OrbitOne.BuildScreen.Configuration.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
</PropertyGroup>
3333
<ItemGroup>
3434
<Reference Include="Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
35+
<Reference Include="Microsoft.TeamFoundation.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
36+
<Reference Include="Microsoft.VisualStudio.Services.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
3537
<Reference Include="Newtonsoft.Json">
3638
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
3739
</Reference>

OrbitOne.BuildScreen/OrbitOne.BuildScreen.Configuration/ServiceConfiguration.cs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text;
1212
using System.Threading.Tasks;
1313
using System.Web;
14+
using Microsoft.TeamFoundation;
1415
using Microsoft.TeamFoundation.Client;
1516
using Newtonsoft.Json;
1617
using Newtonsoft.Json.Linq;
@@ -57,7 +58,7 @@ public static void CreateNewConfiguration()
5758
LogService.WriteError(e);
5859
throw;
5960
}
60-
61+
6162
}
6263
public static void UpdateConfiguration(int id, ServiceConfig ic)
6364
{
@@ -67,7 +68,7 @@ public static void UpdateConfiguration(int id, ServiceConfig ic)
6768
if (configuration == null)
6869
throw new ArgumentException("Configuration with Id \"" + ic.Id + "\" can't be found.");
6970
if (string.IsNullOrEmpty(ic.Password) || ic.Password.Equals(ReturnPassword))
70-
{
71+
{
7172
var password = configuration.Password;
7273
ic.Password = password;
7374
}
@@ -94,7 +95,7 @@ public static ServiceConfig GetConfiguration(int id)
9495
{
9596
LogService.WriteError(e);
9697
throw;
97-
}
98+
}
9899
return configs;
99100
}
100101

@@ -179,7 +180,7 @@ public static List<ServiceConfig> GetListOfConfigurationsNoPassword()
179180
List<ServiceConfig> configs = null;
180181
try
181182
{
182-
configs = GetListOfConfigurationsInternal().Select(c =>{c.Password = ReturnPassword; return c;}).ToList();
183+
configs = GetListOfConfigurationsInternal().Select(c => { c.Password = ReturnPassword; return c; }).ToList();
183184
}
184185
catch (Exception e)
185186
{
@@ -242,6 +243,10 @@ private static string CheckValidityOfConfig(IServiceConfig config)
242243
}
243244
catch (AggregateException e)
244245
{
246+
if (e.InnerException is Exception)
247+
{
248+
return e.InnerException.Message;
249+
}
245250
return "DNS could not find server adress";
246251
}
247252
catch (Exception e)
@@ -254,35 +259,34 @@ private static string CheckValidityOfConfig(IServiceConfig config)
254259
private static async Task<bool> CanLogIn(string username, string password, string uri, string configType)
255260
{
256261
bool response = false;
257-
try
262+
// VSO check
263+
if (configType == "VSO")
258264
{
259-
// VSO check
260-
if (configType == "VSO")
265+
using (var client = new HttpClient())
261266
{
262-
using (var client = new HttpClient())
263-
{
264-
client.BaseAddress = new Uri(uri);
265-
client.DefaultRequestHeaders.Accept.Clear();
266-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
267-
Convert.ToBase64String(
268-
Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password))));
269-
Debug.WriteLine("Code: " + client.GetAsync("").Result.StatusCode);
270-
response = client.GetAsync("").Result.StatusCode == HttpStatusCode.OK;
271-
}
267+
client.BaseAddress = new Uri(uri);
268+
client.DefaultRequestHeaders.Accept.Clear();
269+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
270+
Convert.ToBase64String(
271+
Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password))));
272+
Debug.WriteLine("Code: " + client.GetAsync("").Result.StatusCode);
273+
response = client.GetAsync("").Result.StatusCode == HttpStatusCode.OK;
272274
}
273-
// TFS check
274-
else if (configType == "TFS")
275+
}
276+
// TFS check
277+
else if (configType == "TFS")
278+
{
279+
var credentials = new TfsClientCredentials(new WindowsCredential(new NetworkCredential(username, password)));
280+
var server = new TfsConfigurationServer(new Uri(uri), credentials);
281+
try
275282
{
276-
var credentials = new TfsClientCredentials(new WindowsCredential(new NetworkCredential(username, password)));
277-
var server = new TfsConfigurationServer(new Uri(uri), credentials);
278283
server.EnsureAuthenticated();
279-
response = server.HasAuthenticated;
280284
}
281-
}
282-
catch (Exception e)
283-
{
284-
LogService.WriteError(e);
285-
throw;
285+
catch (TeamFoundationServerUnauthorizedException e)
286+
{
287+
return false;
288+
}
289+
response = server.HasAuthenticated;
286290
}
287291
return response;
288292
}

0 commit comments

Comments
 (0)