microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
321 stars 138 forks source link

Fix error when `_shutdownStatsbeat` gets called while being undefined #1259

Closed mkayander closed 5 months ago

mkayander commented 5 months ago

This PR fixes #1258 issue, a _shutdownStatsbeat function should not be called if it is undefined.

The constructor parameter is optional, however, the according class property is not. There is a nullability check in one of the methods, but not in the res.on("end", ... handler. This causes errors when the callback is not provided.

I've made the class property type nullable as well for convenience, but unfortunately, TS strict mode is turned off in this project. As a result, that kind of nullability issues are not caught by TS.

JacksonWeber commented 5 months ago

Looks good, and makes sense that we need to fix the case where that function could be undefined. Thanks for the contribution!