A bug in version 217.0.0

I believe there is a bug in line 6438 of the purecloud-platform-client-v2.min.js in the following chunk:

                    }, {
                        key: "log",
                        value: function log(level, statusCode, method, url, requestHeaders, responseHeaders, requestBody, responseBody) {
                            var content = this.formatLog(level, statusCode, method, url, requestHeaders, responseHeaders, requestBody, responseBody);
                            if (typeof window !== 'undefined') {
                                var shouldLog = this.calculateLogLevel(level);
                                if (shouldLog > 0 && this.log_to_console === true) {
                                    if (this.log_format === this.logFormatEnum.formats.JSON) {
                                        console.log(content);
                                    } else {
                                        console.log("".concat(level.toUpperCase(), ": ").concat(content));
                                    }
                                }
                            } else {
                                if (this.logger.transports.length > 0)
                                    this.log(level, content);
                            }
                        }

The this is already a Logger object and hence this.logger is undefined. The fix that works for me is

                                if (this.logger?.transports?.length > 0)

but it is probably not the way you'd like to fix the issue.

Hello,

Are you creating a front-end (web) application? Using a framework like React or else?

If yes, that is possibly the origin of the issue - the global window variable not being set/accessible like it'd be in a web browser. I think (not sure as I don't work on these often) that with React and some framework, the window global variable is not accessible via window directly.

If you have some insights on this (how to access window global variable in your case), let me know and I'll see if I can add a more exhaustive test.

We have a single piece of code for nodejs app and for web apps. Testing if window is undefined allows us to determine (guess) if it is for a web app or for a nodejs app.
The code you are showing (if (this.logger.transports.length > 0)) should only be executed if it is a nodejs app (i.e. window is undefined). We leverage a 3rd party lib for logging when it is with nodejs (winston module - available via this.logger - encapsulated in our own Logger class) as it is not supported with web apps (browser).

Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.