@djangocfg/monitor 2.1.231 → 2.1.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.mjs CHANGED
@@ -972,43 +972,47 @@ var _APIClient = class _APIClient {
972
972
  if (error instanceof APIError) {
973
973
  throw error;
974
974
  }
975
- const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
975
+ let possiblyCors = false;
976
+ if (error instanceof TypeError && typeof window !== "undefined") {
977
+ try {
978
+ const isCrossOrigin = (() => {
979
+ try {
980
+ return new URL(url).origin !== window.location.origin;
981
+ } catch {
982
+ return false;
983
+ }
984
+ })();
985
+ if (isCrossOrigin) {
986
+ const entries = performance.getEntriesByName(url, "resource");
987
+ if (entries.length > 0) {
988
+ const last = entries[entries.length - 1];
989
+ possiblyCors = "responseStatus" in last && last.responseStatus === 0;
990
+ }
991
+ }
992
+ } catch {
993
+ }
994
+ }
976
995
  if (this.logger) {
977
- if (isCORSError) {
978
- this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
979
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
980
- this.logger.error(` \u2192 Configure security_domains parameter on the server`);
981
- } else {
982
- this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
983
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
996
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
997
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
998
+ if (possiblyCors) {
999
+ this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
984
1000
  }
985
1001
  }
986
1002
  if (typeof window !== "undefined") {
987
1003
  try {
988
- if (isCORSError) {
989
- window.dispatchEvent(new CustomEvent("cors-error", {
990
- detail: {
991
- url,
992
- method,
993
- error: error instanceof Error ? error.message : String(error),
994
- timestamp: /* @__PURE__ */ new Date()
995
- },
996
- bubbles: true,
997
- cancelable: false
998
- }));
999
- } else {
1000
- window.dispatchEvent(new CustomEvent("network-error", {
1001
- detail: {
1002
- url,
1003
- method,
1004
- error: error instanceof Error ? error.message : String(error),
1005
- timestamp: /* @__PURE__ */ new Date()
1006
- },
1007
- bubbles: true,
1008
- cancelable: false
1009
- }));
1010
- }
1011
- } catch (eventError) {
1004
+ window.dispatchEvent(new CustomEvent("network-error", {
1005
+ detail: {
1006
+ url,
1007
+ method,
1008
+ error: error instanceof Error ? error.message : String(error),
1009
+ possibly_cors: possiblyCors,
1010
+ timestamp: /* @__PURE__ */ new Date()
1011
+ },
1012
+ bubbles: true,
1013
+ cancelable: false
1014
+ }));
1015
+ } catch {
1012
1016
  }
1013
1017
  }
1014
1018
  const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
@@ -1337,7 +1341,7 @@ __name(sendBatch, "sendBatch");
1337
1341
  // src/client/utils/env.ts
1338
1342
  var isDevelopment = true;
1339
1343
  var isProduction = false;
1340
- var MONITOR_VERSION = "2.1.231";
1344
+ var MONITOR_VERSION = "2.1.232";
1341
1345
 
1342
1346
  // src/client/store/index.ts
1343
1347
  var CIRCUIT_BREAKER_THRESHOLD = 3;