Skip to content

Instantly share code, notes, and snippets.

@tmanOC
Created June 23, 2020 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmanOC/db82dba5d01612e92f7bd0b1891aac7c to your computer and use it in GitHub Desktop.
Save tmanOC/db82dba5d01612e92f7bd0b1891aac7c to your computer and use it in GitHub Desktop.
Wrapper for Promise rejections of applicationinsights
appInsights = require("applicationinsights");
let exceptionTrack = appInsights.defaultClient.trackException;
appInsights.defaultClient.trackException = function myExceptionTracker(telemetry) {
let exception = telemetry.exception
//How to test for a Promise
if (Promise.resolve(exception) == exception) {
exception.then(res => {
telemetry.exception = res;
exceptionTrack.call(appInsights.defaultClient, telemetry);
}, err => {
telemetry.exception = err;
exceptionTrack.call(appInsights.defaultClient, telemetry);
}).catch(error => {
telemetry.exception = error;
exceptionTrack.call(appInsights.defaultClient, telemetry);
})
} else {
exceptionTrack.call(appInsights.defaultClient, telemetry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment