Skip to content

Commit 693cff9

Browse files
committed
Added the ability to submit a user description and email address for the event.
1 parent fa387f9 commit 693cff9

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/ExceptionlessClient.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Configuration } from './configuration/Configuration';
33
import { EventBuilder } from './EventBuilder';
44
import { IEvent } from './models/IEvent';
55
import { IError } from './models/IError';
6+
import { IUserDescription } from './models/IUserDescription';
67
import { EventPluginContext } from './plugins/EventPluginContext';
78
import { EventPluginManager } from './plugins/EventPluginManager';
89
import { ContextData } from './plugins/ContextData';
10+
import { SubmissionResponse } from './submission/SubmissionResponse';
911

1012
export class ExceptionlessClient {
1113
public config:Configuration;
@@ -108,6 +110,12 @@ export class ExceptionlessClient {
108110
return new EventBuilder({ date: new Date() }, this, pluginContextData);
109111
}
110112

113+
/**
114+
* Submits the event to be sent to the server.
115+
* @param event The event data.
116+
* @param pluginContextData Any contextual data objects to be used by Exceptionless plugins to gather default information for inclusion in the report information.
117+
* @param callback
118+
*/
111119
public submitEvent(event:IEvent, pluginContextData?:ContextData, callback?:(context:EventPluginContext) => void): void {
112120
if (!event) {
113121
return;
@@ -153,6 +161,37 @@ export class ExceptionlessClient {
153161
});
154162
}
155163

164+
/**
165+
* Updates the user's email address and description of an event for the specified reference id.
166+
* @param referenceId The reference id of the event to update.
167+
* @param email The user's email address to set on the event.
168+
* @param description The user's description of the event.
169+
*/
170+
public updateUserEmailAndDescription(referenceId:string, email:string, description:string, callback?:(response:SubmissionResponse) => void) {
171+
if (!referenceId || !email || !description) {
172+
return;
173+
}
174+
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) => {
181+
if (!response.success) {
182+
this.config.log.error(`Failed to submit user email and description for event '${referenceId}': ${response.statusCode} ${response.message}`)
183+
}
184+
185+
if (!!callback) {
186+
callback(response);
187+
}
188+
});
189+
}
190+
191+
/**
192+
* Gets the last event client id that was submitted to the server.
193+
* @returns {string} The event client id.
194+
*/
156195
public getLastReferenceId(): string {
157196
return this.config.lastReferenceIdManager.getLast();
158197
}

src/submission/SubmissionClientBase.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { SubmissionResponse } from './SubmissionResponse';
99
import { Utils } from '../Utils';
1010

1111
export class SubmissionClientBase implements ISubmissionClient {
12+
public configurationVersionHeader:string = 'X-Exceptionless-ConfigVersion';
13+
1214
public postEvents(events:IEvent[], config:Configuration, callback:(response:SubmissionResponse) => void):void {
1315
return this.sendRequest(config, 'POST', '/api/v2/events', Utils.stringify(events, config.dataExclusions), (status:number, message:string, data?:string, headers?:Object) => {
14-
15-
var settingsVersion = (headers && parseInt(headers['X-Exceptionless-ConfigVersion'])) || -1;
16+
var settingsVersion = (headers && parseInt(headers[this.configurationVersionHeader])) || -1;
1617
SettingsManager.checkVersion(settingsVersion, config);
1718

1819
callback(new SubmissionResponse(status, message));
@@ -21,7 +22,10 @@ export class SubmissionClientBase implements ISubmissionClient {
2122

2223
public postUserDescription(referenceId:string, description:IUserDescription, config:Configuration, callback:(response:SubmissionResponse) => void):void {
2324
var path = `/api/v2/events/by-ref/${encodeURIComponent(referenceId)}/user-description`;
24-
return this.sendRequest(config, 'POST', path, Utils.stringify(description, config.dataExclusions), (status:number, message:string) => {
25+
return this.sendRequest(config, 'POST', path, Utils.stringify(description, config.dataExclusions), (status:number, message:string, data?:string, headers?:Object) => {
26+
var settingsVersion = (headers && parseInt(headers[this.configurationVersionHeader])) || -1;
27+
SettingsManager.checkVersion(settingsVersion, config);
28+
2529
callback(new SubmissionResponse(status, message));
2630
});
2731
}

0 commit comments

Comments
 (0)