Skip to content

Commit

Permalink
[BUG] Circular dependencies #2306 (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev authored Mar 20, 2024
1 parent 0f8f442 commit 2eaa2d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
33 changes: 1 addition & 32 deletions shared/AppInsightsCore/src/JavaScriptSDK/HelperFuncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
import { FeatureOptInMode } from "../JavaScriptSDK.Enums/FeatureOptInEnums";
import { TransportType } from "../JavaScriptSDK.Enums/SendRequestReason";
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
import { IBackendResponse, IXDomainRequest } from "../JavaScriptSDK.Interfaces/IXDomainRequest";
import { _eInternalMessageId, eLoggingSeverity } from "../applicationinsights-core-js";
import { _throwInternal } from "./DiagnosticLogger";
import { getJSON } from "./EnvUtils";
import { IXDomainRequest } from "../JavaScriptSDK.Interfaces/IXDomainRequest";
import { STR_EMPTY } from "./InternalConstants";

// RESTRICT and AVOID circular dependencies you should not import other contained modules or export the contents of this file directly
Expand Down Expand Up @@ -404,33 +400,6 @@ export function prependTransports(theTransports: TransportType[], newTransports:
return theTransports;
}

/**
* Parses the response from the backend.
* @param response - XMLHttpRequest or XDomainRequest response
*/
export function parseResponse(response: any, diagLog?: IDiagnosticLogger): IBackendResponse {
try {
if (response && response !== "") {
const result = getJSON().parse(response);

if (result && result.itemsReceived && result.itemsReceived >= result.itemsAccepted &&
result.itemsReceived - result.itemsAccepted === result.errors.length) {
return result;
}
}
} catch (e) {
_throwInternal(diagLog,
eLoggingSeverity.CRITICAL,
_eInternalMessageId.InvalidBackendResponse,
"Cannot parse the response. " + getExceptionName(e),
{
response
});
}

return null;
}

const strDisabledPropertyName: string = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
const strWithCredentials: string = "withCredentials";
const strTimeout: string = "timeout";
Expand Down
36 changes: 36 additions & 0 deletions shared/AppInsightsCore/src/JavaScriptSDK/ResponseHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { dumpObj } from "@nevware21/ts-utils";
import { _eInternalMessageId, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
import { IBackendResponse } from "../JavaScriptSDK.Interfaces/IXDomainRequest";
import { _throwInternal } from "./DiagnosticLogger";
import { getJSON } from "./EnvUtils";

/**
* Parses the response from the backend.
* @param response - XMLHttpRequest or XDomainRequest response
*/
export function parseResponse(response: any, diagLog?: IDiagnosticLogger): IBackendResponse {
try {
if (response && response !== "") {
const result = getJSON().parse(response);

if (result && result.itemsReceived && result.itemsReceived >= result.itemsAccepted &&
result.itemsReceived - result.itemsAccepted === result.errors.length) {
return result;
}
}
} catch (e) {
_throwInternal(diagLog,
eLoggingSeverity.CRITICAL,
_eInternalMessageId.InvalidBackendResponse,
"Cannot parse the response. " + (e.name || dumpObj(e)),
{
response
});
}

return null;
}
3 changes: 2 additions & 1 deletion shared/AppInsightsCore/src/applicationinsights-core-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export { runTargetUnload, doUnloadAll } from "./JavaScriptSDK/AsyncUtils";
export {
normalizeJsName, toISOString, getExceptionName, strContains, setValue, getSetValue,
proxyAssign, proxyFunctions, proxyFunctionAs, createClassFromInterface, optimizeObject,
isNotUndefined, isNotNullOrUndefined, objExtend, isFeatureEnabled, getResponseText, formatErrorMessageXdr, formatErrorMessageXhr, prependTransports, parseResponse,
isNotUndefined, isNotNullOrUndefined, objExtend, isFeatureEnabled, getResponseText, formatErrorMessageXdr, formatErrorMessageXhr, prependTransports,
openXhr, _appendHeader, _getAllResponseHeaders, convertAllHeadersToMap
} from "./JavaScriptSDK/HelperFuncs";
export { parseResponse } from "./JavaScriptSDK/ResponseHelpers";
export { IXDomainRequest, IBackendResponse } from "./JavaScriptSDK.Interfaces/IXDomainRequest";
export { _ISenderOnComplete, _ISendPostMgrConfig, _ITimeoutOverrideWrapper, _IInternalXhrOverride } from "./JavaScriptSDK.Interfaces/ISenderPostManager";
export { SenderPostManager } from "./JavaScriptSDK/SenderPostManager";
Expand Down

0 comments on commit 2eaa2d5

Please # to comment.