File tree Expand file tree Collapse file tree 6 files changed +107
-0
lines changed Expand file tree Collapse file tree 6 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using Exceptionless . Extensions ;
2
3
using Exceptionless . Extras ;
3
4
using Exceptionless . Models ;
4
5
@@ -10,8 +11,14 @@ public void Run(EventPluginContext context) {
10
11
if ( exception == null )
11
12
return ;
12
13
14
+ if ( exception . IsProcessed ( ) ) {
15
+ context . Cancel = true ;
16
+ return ;
17
+ }
18
+
13
19
context . Event . Type = Event . KnownTypes . Error ;
14
20
context . Event . Data [ Event . KnownDataKeys . Error ] = exception . ToErrorModel ( context . Client ) ;
21
+ exception . MarkProcessed ( ) ;
15
22
}
16
23
}
17
24
}
Original file line number Diff line number Diff line change 4
4
using System . Web . Mvc ;
5
5
using Exceptionless . Dependency ;
6
6
using Exceptionless . Web ;
7
+ using Exceptionless . Web . Extensions ;
7
8
8
9
namespace Exceptionless . Mvc {
9
10
public class ExceptionlessModule : IHttpModule {
10
11
private HttpApplication _app ;
11
12
12
13
public virtual void Init ( HttpApplication app ) {
13
14
ExceptionlessClient . Default . Startup ( ) ;
15
+ ExceptionlessClient . Default . RegisterHttpApplicationErrorHandler ( app ) ;
14
16
ExceptionlessClient . Default . Configuration . AddPlugin < ExceptionlessWebPlugin > ( ) ;
15
17
ExceptionlessClient . Default . Configuration . Resolver . Register < ILastReferenceIdManager , WebLastReferenceIdManager > ( ) ;
16
18
@@ -22,6 +24,7 @@ public virtual void Init(HttpApplication app) {
22
24
23
25
public void Dispose ( ) {
24
26
ExceptionlessClient . Default . Shutdown ( ) ;
27
+ ExceptionlessClient . Default . RegisterHttpApplicationErrorHandler ( _app ) ;
25
28
}
26
29
}
27
30
}
Original file line number Diff line number Diff line change @@ -54,5 +54,32 @@ public static string GetMessage(this Exception exception) {
54
54
55
55
return exception . GetInnermostException ( ) . Message ;
56
56
}
57
+
58
+ private static readonly string _marker = "@exceptionless" ;
59
+ public static void MarkProcessed ( this Exception exception ) {
60
+ if ( exception == null )
61
+ return ;
62
+
63
+ try {
64
+ if ( exception . Data != null ) {
65
+ var genericTypes = exception . Data . GetType ( ) . GetGenericArguments ( ) ;
66
+ exception . Data [ _marker ] = genericTypes . Length > 0 ? genericTypes [ 0 ] . GetDefaultValue ( ) : null ;
67
+ }
68
+ } catch ( Exception ) { }
69
+
70
+ MarkProcessed ( exception . InnerException ) ;
71
+ }
72
+
73
+ public static bool IsProcessed ( this Exception exception ) {
74
+ if ( exception == null )
75
+ return false ;
76
+
77
+ try {
78
+ if ( exception . Data != null && exception . Data . Contains ( _marker ) )
79
+ return true ;
80
+ } catch ( Exception ) { }
81
+
82
+ return IsProcessed ( exception . InnerException ) ;
83
+ }
57
84
}
58
85
}
Original file line number Diff line number Diff line change @@ -35,6 +35,38 @@ public static PropertyInfo[] GetPublicProperties(this Type type) {
35
35
36
36
return type . GetProperties ( BindingFlags . FlattenHierarchy | BindingFlags . Public | BindingFlags . Instance ) ;
37
37
}
38
+
39
+ public static object GetDefaultValue ( this Type type ) {
40
+ if ( type == null || type . IsNullable ( ) )
41
+ return null ;
42
+
43
+ if ( type == typeof ( bool ) )
44
+ return default ( bool ) ;
45
+ if ( type == typeof ( byte ) )
46
+ return default ( byte ) ;
47
+ if ( type == typeof ( char ) )
48
+ return default ( char ) ;
49
+ if ( type == typeof ( decimal ) )
50
+ return default ( decimal ) ;
51
+ if ( type == typeof ( double ) )
52
+ return default ( double ) ;
53
+ if ( type == typeof ( float ) )
54
+ return default ( float ) ;
55
+ if ( type == typeof ( int ) )
56
+ return default ( int ) ;
57
+ if ( type == typeof ( long ) )
58
+ return default ( long ) ;
59
+ if ( type == typeof ( sbyte ) )
60
+ return default ( sbyte ) ;
61
+ if ( type == typeof ( uint ) )
62
+ return default ( uint ) ;
63
+ if ( type == typeof ( ulong ) )
64
+ return default ( ulong ) ;
65
+ if ( type == typeof ( ushort ) )
66
+ return default ( ushort ) ;
67
+
68
+ return Activator . CreateInstance ( type ) ;
69
+ }
38
70
39
71
public static bool IsNullable ( this Type type ) {
40
72
if ( type . IsValueType )
Original file line number Diff line number Diff line change @@ -10,8 +10,14 @@ public void Run(EventPluginContext context) {
10
10
if ( exception == null )
11
11
return ;
12
12
13
+ if ( exception . IsProcessed ( ) ) {
14
+ context . Cancel = true ;
15
+ return ;
16
+ }
17
+
13
18
context . Event . Type = Event . KnownTypes . Error ;
14
19
context . Event . Data [ Event . KnownDataKeys . SimpleError ] = exception . ToSimpleErrorModel ( context . Client ) ;
20
+ exception . MarkProcessed ( ) ;
15
21
}
16
22
}
17
23
}
Original file line number Diff line number Diff line change @@ -58,6 +58,38 @@ public void ConfigurationDefaults_IgnoredProperties() {
58
58
Assert . Equal ( "Test" , context . Event . Data [ "Message" ] ) ;
59
59
}
60
60
61
+ [ Fact ]
62
+ public void ErrorPlugin_DiscardDuplicates ( ) {
63
+ var errorPlugins = new List < IEventPlugin > {
64
+ new ErrorPlugin ( ) ,
65
+ new SimpleErrorPlugin ( )
66
+ } ;
67
+
68
+ foreach ( var plugin in errorPlugins ) {
69
+ var exception = new Exception ( "Nested" , new MyApplicationException ( "Test" ) {
70
+ IgnoredProperty = "Test" ,
71
+ RandomValue = "Test"
72
+ } ) ;
73
+
74
+ var client = new ExceptionlessClient ( ) ;
75
+ var context = new EventPluginContext ( client , new Event ( ) ) ;
76
+ context . ContextData . SetException ( exception ) ;
77
+ plugin . Run ( context ) ;
78
+ Assert . False ( context . Cancel ) ;
79
+
80
+ IData error = context . Event . GetError ( ) as IData ?? context . Event . GetSimpleError ( ) ;
81
+ Assert . NotNull ( error ) ;
82
+
83
+ context = new EventPluginContext ( client , new Event ( ) ) ;
84
+ context . ContextData . SetException ( exception ) ;
85
+ plugin . Run ( context ) ;
86
+ Assert . True ( context . Cancel ) ;
87
+
88
+ error = context . Event . GetError ( ) as IData ?? context . Event . GetSimpleError ( ) ;
89
+ Assert . Null ( error ) ;
90
+ }
91
+ }
92
+
61
93
[ Fact ]
62
94
public void ErrorPlugin_IgnoredProperties ( ) {
63
95
var exception = new MyApplicationException ( "Test" ) {
You can’t perform that action at this time.
0 commit comments