Skip to content

Commit ee353e5

Browse files
mfahadahmedmikeproeng37
authored andcommitted
feat(eventdispatcher): HttpClientEventDispatcher45 now logs full exception (#112)
1 parent 1840d1e commit ee353e5

File tree

8 files changed

+85
-9
lines changed

8 files changed

+85
-9
lines changed

OptimizelySDK.Net35/OptimizelySDK.Net35.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,13 @@
172172
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs">
173173
<Link>Utils\ControlAttributes.cs</Link>
174174
</Compile>
175-
<Compile Include="..\OptimizelySDK\Utils\ConditionParser.cs">
175+
<Compile Include="..\OptimizelySDK\Utils\ExceptionExtensions.cs">
176+
<Link>Utils\ExceptionExtensions.cs</Link>
177+
</Compile>
178+
<Compile Include="..\OptimizelySDK\Utils\ConditionParser.cs">
176179
<Link>Utils\ConditionParser.cs</Link>
177180
</Compile>
178-
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs">
181+
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs">
179182
<Link>Utils\AttributeMatchTypes.cs</Link>
180183
</Compile>
181184
<Compile Include="Properties\AssemblyInfo.cs" />

OptimizelySDK.Net40/OptimizelySDK.Net40.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@
176176
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs">
177177
<Link>Utils\ControlAttributes.cs</Link>
178178
</Compile>
179-
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs">
179+
<Compile Include="..\OptimizelySDK\Utils\ExceptionExtensions.cs">
180+
<Link>Utils\ExceptionExtensions.cs</Link>
181+
</Compile>
182+
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs">
180183
<Link>Utils\AttributeMatchTypes.cs</Link>
181184
</Compile>
182185
<Compile Include="Properties\AssemblyInfo.cs" />

OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555
<Compile Include="..\OptimizelySDK\Utils\Validator.cs" />
5656
<Compile Include="..\OptimizelySDK\Utils\ConfigParser.cs" />
5757
<Compile Include="..\OptimizelySDK\Utils\Schema.cs" />
58-
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs" />
59-
<Compile Include="..\OptimizelySDK\Utils\ExperimentUtils.cs" />
60-
<Compile Include="..\OptimizelySDK\Utils\ConditionParser.cs" />
61-
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs" />
58+
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs" />
59+
<Compile Include="..\OptimizelySDK\Utils\ExceptionExtensions.cs" />
60+
<Compile Include="..\OptimizelySDK\Utils\ExperimentUtils.cs" />
61+
<Compile Include="..\OptimizelySDK\Utils\ConditionParser.cs" />
62+
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs" />
6263
<Compile Include="..\OptimizelySDK\Bucketing\Bucketer.cs" />
6364
<Compile Include="..\OptimizelySDK\Bucketing\Decision.cs" />
6465
<Compile Include="..\OptimizelySDK\Bucketing\DecisionService.cs" />

OptimizelySDK.Tests/OptimizelySDK.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<Compile Include="ProjectConfigTest.cs" />
8888
<Compile Include="UtilsTests\ConditionParserTest.cs" />
8989
<Compile Include="UtilsTests\EventTagUtilsTest.cs" />
90+
<Compile Include="UtilsTests\ExceptionExtensionsTest.cs" />
9091
<Compile Include="UtilsTests\ExperimentUtilsTest.cs" />
9192
<Compile Include="UtilsTests\PrivateObject.cs" />
9293
<Compile Include="UtilsTests\ValidatorTest.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using NUnit.Framework;
18+
using OptimizelySDK.Utils;
19+
using System;
20+
21+
namespace OptimizelySDK.Tests.UtilsTests
22+
{
23+
public class ExceptionExtensionsTest
24+
{
25+
[Test]
26+
public void TestGetAllMessagesReturnsAllInnerExceptionMessages()
27+
{
28+
var exception = new Exception("Outer exception.", new Exception("Inner exception.", new Exception("Second level inner exception.")));
29+
var expectedMessage = "Outer exception.\nInner exception.\nSecond level inner exception.";
30+
31+
Assert.AreEqual(expectedMessage, exception.GetAllMessages());
32+
}
33+
}
34+
}

OptimizelySDK/Event/Dispatcher/HttpClientEventDispatcher45.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017, Optimizely
2+
* Copyright 2017, 2019, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
#if !NET35 && !NET40
1717
using OptimizelySDK.Logger;
18+
using OptimizelySDK.Utils;
1819
using System;
1920
using System.Net.Http;
2021
using System.Threading.Tasks;
@@ -63,7 +64,7 @@ private async void DispatchEventAsync(LogEvent logEvent)
6364
}
6465
catch (Exception ex)
6566
{
66-
Logger.Log(LogLevel.ERROR, string.Format("Error Dispatching Event: {0}", ex.Message));
67+
Logger.Log(LogLevel.ERROR, string.Format("Error Dispatching Event: {0}", ex.GetAllMessages()));
6768
}
6869
}
6970

OptimizelySDK/OptimizelySDK.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<Compile Include="Bucketing\UserProfileUtil.cs" />
114114
<Compile Include="Utils\ExperimentUtils.cs" />
115115
<Compile Include="Utils\ControlAttributes.cs" />
116+
<Compile Include="Utils\ExceptionExtensions.cs" />
116117
<Compile Include="Utils\Validator.cs" />
117118
<Compile Include="Properties\AssemblyInfo.cs" />
118119
<Compile Include="Utils\ConfigParser.cs" />
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
19+
namespace OptimizelySDK.Utils
20+
{
21+
public static class ExceptionExtensions
22+
{
23+
public static string GetAllMessages(this Exception exception, string separator = "\n")
24+
{
25+
if (exception.InnerException == null)
26+
return exception.Message;
27+
28+
return (string.IsNullOrEmpty(exception.Message) ? "" : string.Format("{0}{1}", exception.Message, separator))
29+
+ GetAllMessages(exception.InnerException, separator);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)