Created
June 23, 2020 06:44
-
-
Save tmanOC/db82dba5d01612e92f7bd0b1891aac7c to your computer and use it in GitHub Desktop.
Wrapper for Promise rejections of applicationinsights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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