Skip to content

Commit 1be9e92

Browse files
author
rhart
committed
Add error message to report
1 parent 6fc3d4a commit 1be9e92

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

spec/stacktrace-spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,16 @@ describe('StackTrace', function() {
194194

195195
it('sends POST request to given URL', function(done) {
196196
var url = 'http://domain.ext/endpoint';
197+
var errorMsg = 'BOOM';
197198
var stackframes = [new StackFrame('fn', undefined, 'file.js', 32, 1)];
198199

199-
StackTrace.report(stackframes, url).then(callback, done.fail)['catch'](done.fail);
200+
StackTrace.report(errorMsg, stackframes, url).then(callback, done.fail)['catch'](done.fail);
200201

201202
var postRequest = jasmine.Ajax.requests.mostRecent();
202203
postRequest.respondWith({status: 201, contentType: 'text/plain', responseText: 'OK'});
203204

204205
function callback() {
205-
expect(postRequest.data()).toEqual({stack: stackframes});
206+
expect(postRequest.data()).toEqual({message: errorMsg, stack: stackframes});
206207
expect(postRequest.method).toBe('post');
207208
expect(postRequest.url).toBe(url);
208209
done();
@@ -211,10 +212,11 @@ describe('StackTrace', function() {
211212

212213
it('rejects if POST request fails', function(done) {
213214
var url = 'http://domain.ext/endpoint';
215+
var errorMsg = 'BOOM';
214216
var stackframes = [new StackFrame('fn', undefined, 'file.js', 32, 1)];
215217

216218
jasmine.Ajax.stubRequest(url).andError();
217-
StackTrace.report(stackframes, url).then(done.fail, done)['catch'](done);
219+
StackTrace.report(errorMsg, stackframes, url).then(done.fail, done)['catch'](done);
218220
});
219221
});
220222
});

stacktrace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@
163163
},
164164

165165
/**
166-
* Given an Array of StackFrames, serialize and POST to given URL.
166+
* Given an error message and Array of StackFrames, serialize and POST to given URL.
167167
*
168168
* @param {Array} stackframes
169169
* @param {String} url
170170
*/
171-
report: function StackTrace$$report(stackframes, url) {
171+
report: function StackTrace$$report(errorMsg, stackframes, url) {
172172
return new Promise(function(resolve, reject) {
173173
var req = new XMLHttpRequest();
174174
req.onerror = reject;
@@ -183,7 +183,7 @@
183183
};
184184
req.open('post', url);
185185
req.setRequestHeader('Content-Type', 'application/json');
186-
req.send(JSON.stringify({stack: stackframes}));
186+
req.send(JSON.stringify({message: errorMsg, stack: stackframes}));
187187
});
188188
}
189189
};

0 commit comments

Comments
 (0)