Skip to content

Commit

Permalink
[BUG] error logging an error--need to null-check reason #1610
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Jul 14, 2021
1 parent 552b046 commit c06203c
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ function _dispatchEvent(target:EventTarget, evnt: Event) {
}
}

function _getReason(error: any) {
if (error && error.reason) {
const reason = error.reason;
if (!isString(reason) && isFunction(reason.toString)) {
return reason.toString();
}

return dumpObj(reason);
}

// Pass the original object down which will eventually get evaluated for any message or description
return error || "";
}

export class ApplicationInsights extends BaseTelemetryPlugin implements IAppInsights, IAppInsightsInternal {
public static Version = "2.6.4"; // Not currently used anywhere

Expand Down Expand Up @@ -614,7 +628,7 @@ export class ApplicationInsights extends BaseTelemetryPlugin implements IAppInsi
const handled = originalOnUnhandledRejection && (originalOnUnhandledRejection.call(_window, error) as any);
if (handled !== true) { // handled could be typeof function
instance._onerror(Exception.CreateAutoException(
error.reason.toString(),
_getReason(error),
_location ? _location.href : "",
0,
0,
Expand Down

0 comments on commit c06203c

Please sign in to comment.