Skip to content

Commit b82a3c9

Browse files
committed
Ensure callbacks are called when submission fails or is cancelled.
1 parent 693cff9 commit b82a3c9

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/ExceptionlessClient.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,21 @@ export class ExceptionlessClient {
117117
* @param callback
118118
*/
119119
public submitEvent(event:IEvent, pluginContextData?:ContextData, callback?:(context:EventPluginContext) => void): void {
120+
function cancelled() {
121+
if (!!context) {
122+
context.cancelled = true;
123+
}
124+
125+
return !!callback && callback(context);
126+
}
127+
120128
if (!event) {
121-
return;
129+
return cancelled();
122130
}
123131

124132
if (!this.config.enabled) {
125-
return this.config.log.info('Event submission is currently disabled.');
133+
this.config.log.info('Event submission is currently disabled.');
134+
return cancelled();
126135
}
127136

128137
if (!event.data) {
@@ -155,9 +164,7 @@ export class ExceptionlessClient {
155164
}
156165
}
157166

158-
if (!!callback) {
159-
callback(context);
160-
}
167+
!!callback && callback(context);
161168
});
162169
}
163170

@@ -168,23 +175,17 @@ export class ExceptionlessClient {
168175
* @param description The user's description of the event.
169176
*/
170177
public updateUserEmailAndDescription(referenceId:string, email:string, description:string, callback?:(response:SubmissionResponse) => void) {
171-
if (!referenceId || !email || !description) {
172-
return;
178+
if (!referenceId || !email || !description || !this.config.enabled) {
179+
return !!callback && callback(new SubmissionResponse(500, 'cancelled'));
173180
}
174181

175-
if (!this.config.enabled) {
176-
return this.config.log.info('Configuration is disabled. The event will not be updated with the user email and description.');
177-
}
178-
179-
var description:IUserDescription = { email: email, description: description };
180-
var response = this.config.submissionClient.postUserDescription(referenceId, description, this.config, (response:SubmissionResponse) => {
182+
var userDescription:IUserDescription = { email_address: email, description: description };
183+
var response = this.config.submissionClient.postUserDescription(referenceId, userDescription, this.config, (response:SubmissionResponse) => {
181184
if (!response.success) {
182185
this.config.log.error(`Failed to submit user email and description for event '${referenceId}': ${response.statusCode} ${response.message}`)
183186
}
184187

185-
if (!!callback) {
186-
callback(response);
187-
}
188+
!!callback && callback(response);
188189
});
189190
}
190191

@@ -201,6 +202,7 @@ export class ExceptionlessClient {
201202
if(ExceptionlessClient._instance === null) {
202203
ExceptionlessClient._instance = new ExceptionlessClient(null);
203204
}
205+
204206
return ExceptionlessClient._instance;
205207
}
206208
}

src/exceptionless.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
// TODO: Verify that stack traces are parsed properly.
2-
// TODO: Handle Server Settings
3-
// TODO: Lock configuration.
4-
// TODO: Move this into an static array and dynamically call all registered bootstrappers.
5-
// TODO: NODE: modules.
6-
// TODO: Filter excluded properties.
7-
// TODO: Get extra exception properties.
8-
91
import { IBootstrapper } from './bootstrap/IBootstrapper';
102
import { NodeBootstrapper } from './bootstrap/NodeBootstrapper';
113
import { WindowBootstrapper } from './bootstrap/WindowBootstrapper';

0 commit comments

Comments
 (0)