Skip to content

Commit f549a50

Browse files
Jastrzebowskisteren
authored andcommitted
Print console warning when stack trace is missing
* Fail gracefully if stacktrace-js is missing #26
1 parent ed198bb commit f549a50

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

stackdriver-errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
if(!config.projectId && !config.targetUrl) {
4747
throw new Error('Cannot initialize: No project ID or target url provided.');
4848
}
49+
if(typeof StackTrace === 'undefined') {
50+
// Inform about missing dependency
51+
throw new Error('make sure you loaded “dist/stackdriver-errors-concat.js” or “dist/stackdriver-errors-concat.min.js”, or that you imported the “stacktrace-js” module');
52+
}
4953

5054
this.apiKey = config.key;
5155
this.projectId = config.projectId;

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ describe('Initialization', function () {
7777
expect(function() {errorHandler.start({key:'key'});}).to.throw(Error, /project/);
7878
});
7979

80+
it('should fail if StackTrace is undefined', function () {
81+
var stackTrace = window.StackTrace;
82+
delete window.StackTrace;
83+
expect(function() {errorHandler.start({projectId:'projectId', key:'key'});}).to.throw(Error, /stackdriver-errors-concat/);
84+
window.StackTrace = stackTrace;
85+
});
86+
8087
it('should succeed if custom target url provided without API key or project id', function () {
8188
expect(function() {errorHandler.start({targetUrl:'custom-url'});}).to.not.throw();
8289
});

0 commit comments

Comments
 (0)