66// TODO: Handle Server Settings
77// TODO: Lock configuration.
88// TODO: Look into using templated strings `${1 + 1}`.
9- // TODO: Add plugin for populating module info.
109
1110module Exceptionless {
1211 export class ExceptionlessClient {
@@ -22,8 +21,8 @@ module Exceptionless {
2221 return this . createEvent ( pluginContextData ) . setType ( 'error' ) ;
2322 }
2423
25- public submitException ( exception :Error ) : void {
26- this . createException ( exception ) . submit ( ) ;
24+ public submitException ( exception :Error ) : Promise < any > {
25+ return this . createException ( exception ) . submit ( ) ;
2726 }
2827
2928 public createUnhandledException ( exception :Error ) : EventBuilder {
@@ -33,16 +32,16 @@ module Exceptionless {
3332 return builder ;
3433 }
3534
36- public submitUnhandledException ( exception :Error ) : void {
37- this . createUnhandledException ( exception ) . submit ( ) ;
35+ public submitUnhandledException ( exception :Error ) : Promise < any > {
36+ return this . createUnhandledException ( exception ) . submit ( ) ;
3837 }
3938
4039 public createFeatureUsage ( feature :string ) : EventBuilder {
4140 return this . createEvent ( ) . setType ( 'usage' ) . setSource ( feature ) ;
4241 }
4342
44- public submitFeatureUsage ( feature :string ) : void {
45- this . createFeatureUsage ( feature ) . submit ( ) ;
43+ public submitFeatureUsage ( feature :string ) : Promise < any > {
44+ return this . createFeatureUsage ( feature ) . submit ( ) ;
4645 }
4746
4847 public createLog ( message :string ) : EventBuilder ;
@@ -64,57 +63,59 @@ module Exceptionless {
6463 return builder ;
6564 }
6665
67- public submitLog ( message :string ) : void ;
68- public submitLog ( source :string , message :string ) : void ;
69- public submitLog ( source :string , message :string , level :string ) : void ;
70- public submitLog ( sourceOrMessage :string , message ?:string , level ?:string ) : void {
71- this . createLog ( sourceOrMessage , message , level ) . submit ( ) ;
66+ public submitLog ( message :string ) : Promise < any > ;
67+ public submitLog ( source :string , message :string ) : Promise < any > ;
68+ public submitLog ( source :string , message :string , level :string ) : Promise < any > ;
69+ public submitLog ( sourceOrMessage :string , message ?:string , level ?:string ) : Promise < any > {
70+ return this . createLog ( sourceOrMessage , message , level ) . submit ( ) ;
7271 }
7372
7473 public createNotFound ( resource :string ) : EventBuilder {
7574 return this . createEvent ( ) . setType ( '404' ) . setSource ( resource ) ;
7675 }
7776
78- public submitNotFound ( resource :string ) : void {
79- this . createNotFound ( resource ) . submit ( ) ;
77+ public submitNotFound ( resource :string ) : Promise < any > {
78+ return this . createNotFound ( resource ) . submit ( ) ;
8079 }
8180
8281 public createSessionStart ( sessionId :string ) : EventBuilder {
8382 return this . createEvent ( ) . setType ( 'start' ) . setSessionId ( sessionId ) ;
8483 }
8584
86- public submitSessionStart ( sessionId :string ) : void {
87- this . createSessionStart ( sessionId ) . submit ( ) ;
85+ public submitSessionStart ( sessionId :string ) : Promise < any > {
86+ return this . createSessionStart ( sessionId ) . submit ( ) ;
8887 }
8988
9089 public createSessionEnd ( sessionId :string ) : EventBuilder {
9190 return this . createEvent ( ) . setType ( 'end' ) . setSessionId ( sessionId ) ;
9291 }
9392
94- public submitSessionEnd ( sessionId :string ) : void {
95- this . createSessionEnd ( sessionId ) . submit ( ) ;
93+ public submitSessionEnd ( sessionId :string ) : Promise < any > {
94+ return this . createSessionEnd ( sessionId ) . submit ( ) ;
9695 }
9796
9897 public createEvent ( pluginContextData ?:ContextData ) : EventBuilder {
9998 return new EventBuilder ( { date : new Date ( ) } , this , pluginContextData ) ;
10099 }
101100
102- public submitEvent ( event :IEvent , pluginContextData ?:ContextData ) {
101+ public submitEvent ( event :IEvent , pluginContextData ?:ContextData ) : Promise < any > {
103102 if ( ! event ) {
104- return ;
103+ return Promise . reject ( new Error ( 'Unable to submit undefined event.' ) ) ;
105104 }
106105
107106 if ( ! this . config . enabled ) {
108- this . config . log . info ( 'Event submission is currently disabled' ) ;
109- return ;
107+ var message :string = 'Event submission is currently disabled.' ;
108+ this . config . log . info ( message ) ;
109+ return Promise . reject ( new Error ( message ) ) ;
110110 }
111111
112112 var context = new EventPluginContext ( this , event , pluginContextData ) ;
113- EventPluginManager . run ( context )
113+ return EventPluginManager . run ( context )
114114 . then ( ( ) => {
115115 if ( context . cancel ) {
116- context . log . info ( 'Event submission cancelled by plugin": id=' + event . reference_id + ' type=' + event . type ) ;
117- return ;
116+ var message :string = 'Event submission cancelled by plugin": id=' + event . reference_id + ' type=' + event . type ;
117+ this . config . log . info ( message ) ;
118+ return Promise . reject ( new Error ( message ) ) ;
118119 }
119120
120121 // ensure all required data
@@ -129,16 +130,17 @@ module Exceptionless {
129130 this . config . log . info ( 'Submitting event: type=' + event . type + ! ! event . reference_id ? ' refid=' + event . reference_id : '' ) ;
130131 this . config . queue . enqueue ( event ) ;
131132
132- if ( ! event . reference_id || event . reference_id . length === 0 ) {
133- return ;
133+ if ( event . reference_id && event . reference_id . length > 0 ) {
134+ this . config . log . info ( 'Setting last reference id "' + event . reference_id + '"' ) ;
135+ this . config . lastReferenceIdManager . setLast ( event . reference_id ) ;
134136 }
135137
136- this . config . log . info ( 'Setting last reference id "' + event . reference_id + '"' ) ;
137- this . config . lastReferenceIdManager . setLast ( event . reference_id ) ;
138+ return Promise . resolve ( ) ;
138139 } )
139140 . catch ( ( error :Error ) => {
140- var message :string = error && error . message ? error . message : < any > error ;
141- this . config . log . error ( 'Event submission cancelled. An error occurred while running the plugins: ' + message ) ;
141+ var message :string = 'Event submission cancelled. An error occurred while running the plugins: ' + error && error . message ? error . message : < any > error ;
142+ this . config . log . error ( message ) ;
143+ return Promise . reject ( new Error ( message ) ) ;
142144 } ) ;
143145 }
144146
@@ -865,8 +867,8 @@ module Exceptionless {
865867 return this ;
866868 }
867869
868- public submit ( ) : void {
869- this . client . submitEvent ( this . target , this . pluginContextData ) ;
870+ public submit ( ) : Promise < any > {
871+ return this . client . submitEvent ( this . target , this . pluginContextData ) ;
870872 }
871873
872874 private isValidIdentifier ( value :string ) : boolean {
@@ -1078,7 +1080,7 @@ module Exceptionless {
10781080 }
10791081 }
10801082
1081- class ModuleInfoPlugin implements IEventPlugin {
1083+ export class ModuleInfoPlugin implements IEventPlugin {
10821084 public priority :number = 40 ;
10831085 public name :string = 'ModuleInfoPlugin' ;
10841086
@@ -1109,7 +1111,7 @@ module Exceptionless {
11091111 return Promise . resolve ( ) ;
11101112 }
11111113
1112- private getVersion ( source :string ) : string {
1114+ public getVersion ( source :string ) : string {
11131115 if ( ! source ) {
11141116 return null ;
11151117 }
@@ -1123,7 +1125,7 @@ module Exceptionless {
11231125 return null ;
11241126 }
11251127
1126- private getHashCode ( source :string ) : string {
1128+ public getHashCode ( source :string ) : string {
11271129 if ( ! source || source . length === 0 ) {
11281130 return null ;
11291131 }
0 commit comments