This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ripped out FlattenException into a separate extension method
- Loading branch information
Showing
5 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Nancy.Helpers | ||
{ | ||
using System; | ||
|
||
internal static class ExceptionExtensions | ||
{ | ||
internal static Exception FlattenInnerExceptions(this Exception exception) | ||
{ | ||
var aggregateException = exception as AggregateException; | ||
if (aggregateException != null) | ||
{ | ||
var flattenedAggregateException = aggregateException.Flatten(); | ||
|
||
//If we have more than one exception in the AggregateException | ||
//we have to send all exceptions back in order not to swallow any exceptions. | ||
if (flattenedAggregateException.InnerExceptions.Count > 1) | ||
{ | ||
return flattenedAggregateException; | ||
} | ||
|
||
return flattenedAggregateException.InnerException.FlattenInnerExceptions(); | ||
} | ||
|
||
if (exception != null && exception.InnerException != null) | ||
{ | ||
return exception.InnerException.FlattenInnerExceptions(); | ||
} | ||
|
||
return exception; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters