@@ -2,14 +2,20 @@ import { IConfigurationSettings } from './configuration/IConfigurationSettings';
2
2
import { Configuration } from './configuration/Configuration' ;
3
3
import { EventBuilder } from './EventBuilder' ;
4
4
import { IEvent } from './models/IEvent' ;
5
- import { IError } from './models/IError' ;
6
5
import { IUserDescription } from './models/IUserDescription' ;
7
6
import { EventPluginContext } from './plugins/EventPluginContext' ;
8
7
import { EventPluginManager } from './plugins/EventPluginManager' ;
9
8
import { ContextData } from './plugins/ContextData' ;
10
9
import { SubmissionResponse } from './submission/SubmissionResponse' ;
11
10
12
11
export class ExceptionlessClient {
12
+ /**
13
+ * The default ExceptionlessClient instance.
14
+ * @type {ExceptionlessClient }
15
+ * @private
16
+ */
17
+ private static _instance :ExceptionlessClient = null ;
18
+
13
19
public config :Configuration ;
14
20
15
21
constructor ( ) ;
@@ -24,7 +30,7 @@ export class ExceptionlessClient {
24
30
}
25
31
26
32
public createException ( exception :Error ) : EventBuilder {
27
- var pluginContextData = new ContextData ( ) ;
33
+ let pluginContextData = new ContextData ( ) ;
28
34
pluginContextData . setException ( exception ) ;
29
35
return this . createEvent ( pluginContextData ) . setType ( 'error' ) ;
30
36
}
@@ -34,7 +40,7 @@ export class ExceptionlessClient {
34
40
}
35
41
36
42
public createUnhandledException ( exception :Error , submissionMethod ?:string ) : EventBuilder {
37
- var builder = this . createException ( exception ) ;
43
+ let builder = this . createException ( exception ) ;
38
44
builder . pluginContextData . markAsUnhandledError ( ) ;
39
45
builder . pluginContextData . setSubmissionMethod ( submissionMethod ) ;
40
46
@@ -57,15 +63,15 @@ export class ExceptionlessClient {
57
63
public createLog ( source :string , message :string ) : EventBuilder ;
58
64
public createLog ( source :string , message :string , level :string ) : EventBuilder ;
59
65
public createLog ( sourceOrMessage :string , message ?:string , level ?:string ) : EventBuilder {
60
- var builder = this . createEvent ( ) . setType ( 'log' ) ;
66
+ let builder = this . createEvent ( ) . setType ( 'log' ) ;
61
67
62
68
if ( message && level ) {
63
69
builder = builder . setSource ( sourceOrMessage ) . setMessage ( message ) . setProperty ( '@level' , level ) ;
64
70
} else if ( message ) {
65
71
builder = builder . setSource ( sourceOrMessage ) . setMessage ( message ) ;
66
72
} else {
67
73
// TODO: Look into using https://www.stevefenton.co.uk/Content/Blog/Date/201304/Blog/Obtaining-A-Class-Name-At-Runtime-In-TypeScript/
68
- var caller :any = arguments . callee . caller ;
74
+ let caller :any = arguments . callee . caller ;
69
75
builder = builder . setSource ( caller && caller . name ) . setMessage ( sourceOrMessage ) ;
70
76
}
71
77
@@ -114,21 +120,22 @@ export class ExceptionlessClient {
114
120
* @param callback
115
121
*/
116
122
public submitEvent ( event :IEvent , pluginContextData ?:ContextData , callback ?:( context :EventPluginContext ) => void ) : void {
117
- function cancelled ( ) {
123
+ function cancelled ( context : EventPluginContext ) {
118
124
if ( ! ! context ) {
119
125
context . cancelled = true ;
120
126
}
121
127
122
128
return ! ! callback && callback ( context ) ;
123
129
}
124
130
131
+ let context = new EventPluginContext ( this , event , pluginContextData ) ;
125
132
if ( ! event ) {
126
- return cancelled ( ) ;
133
+ return cancelled ( context ) ;
127
134
}
128
135
129
136
if ( ! this . config . enabled ) {
130
137
this . config . log . info ( 'Event submission is currently disabled.' ) ;
131
- return cancelled ( ) ;
138
+ return cancelled ( context ) ;
132
139
}
133
140
134
141
if ( ! event . data ) {
@@ -139,10 +146,9 @@ export class ExceptionlessClient {
139
146
event . tags = [ ] ;
140
147
}
141
148
142
- var context = new EventPluginContext ( this , event , pluginContextData ) ;
143
- EventPluginManager . run ( context , function ( context :EventPluginContext ) {
144
- let ev = context . event ;
145
- if ( ! context . cancelled ) {
149
+ EventPluginManager . run ( context , function ( ctx :EventPluginContext ) {
150
+ let ev = ctx . event ;
151
+ if ( ! ctx . cancelled ) {
146
152
// ensure all required data
147
153
if ( ! ev . type || ev . type . length === 0 ) {
148
154
ev . type = 'log' ;
@@ -152,16 +158,16 @@ export class ExceptionlessClient {
152
158
ev . date = new Date ( ) ;
153
159
}
154
160
155
- var config = context . client . config ;
161
+ let config = ctx . client . config ;
156
162
config . queue . enqueue ( ev ) ;
157
163
158
164
if ( ev . reference_id && ev . reference_id . length > 0 ) {
159
- context . log . info ( `Setting last reference id '${ ev . reference_id } '` ) ;
165
+ ctx . log . info ( `Setting last reference id '${ ev . reference_id } '` ) ;
160
166
config . lastReferenceIdManager . setLast ( ev . reference_id ) ;
161
167
}
162
168
}
163
169
164
- ! ! callback && callback ( context ) ;
170
+ ! ! callback && callback ( ctx ) ;
165
171
} ) ;
166
172
}
167
173
@@ -176,10 +182,10 @@ export class ExceptionlessClient {
176
182
return ! ! callback && callback ( new SubmissionResponse ( 500 , 'cancelled' ) ) ;
177
183
}
178
184
179
- var userDescription :IUserDescription = { email_address : email , description : description } ;
180
- var response = this . config . submissionClient . postUserDescription ( referenceId , userDescription , this . config , ( response :SubmissionResponse ) => {
185
+ let userDescription :IUserDescription = { email_address : email , description : description } ;
186
+ this . config . submissionClient . postUserDescription ( referenceId , userDescription , this . config , ( response :SubmissionResponse ) => {
181
187
if ( ! response . success ) {
182
- this . config . log . error ( `Failed to submit user email and description for event '${ referenceId } ': ${ response . statusCode } ${ response . message } ` )
188
+ this . config . log . error ( `Failed to submit user email and description for event '${ referenceId } ': ${ response . statusCode } ${ response . message } ` ) ;
183
189
}
184
190
185
191
! ! callback && callback ( response ) ;
@@ -194,20 +200,12 @@ export class ExceptionlessClient {
194
200
return this . config . lastReferenceIdManager . getLast ( ) ;
195
201
}
196
202
197
- /**
198
- * The default ExceptionlessClient instance.
199
- * @type {ExceptionlessClient }
200
- * @private
201
- */
202
- private static _instance :ExceptionlessClient = null ;
203
-
204
-
205
203
/**
206
204
* The default ExceptionlessClient instance.
207
205
* @type {ExceptionlessClient }
208
206
*/
209
207
public static get default ( ) {
210
- if ( ExceptionlessClient . _instance === null ) {
208
+ if ( ExceptionlessClient . _instance === null ) {
211
209
ExceptionlessClient . _instance = new ExceptionlessClient ( null ) ;
212
210
}
213
211
0 commit comments