@djangocfg/monitor 2.1.231 → 2.1.233

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/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <div align="center">
2
+
3
+ ![@djangocfg/monitor](https://raw.githubusercontent.com/markolofsen/assets/main/libs/djangocfg/monitor.webp)
4
+
5
+ </div>
6
+
1
7
  # @djangocfg/monitor
2
8
 
3
9
  Browser + server error monitoring SDK for [DjangoCFG](https://djangocfg.com) backends.
package/dist/client.cjs CHANGED
@@ -995,43 +995,47 @@ var _APIClient = class _APIClient {
995
995
  if (error instanceof APIError) {
996
996
  throw error;
997
997
  }
998
- const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
998
+ let possiblyCors = false;
999
+ if (error instanceof TypeError && typeof window !== "undefined") {
1000
+ try {
1001
+ const isCrossOrigin = (() => {
1002
+ try {
1003
+ return new URL(url).origin !== window.location.origin;
1004
+ } catch {
1005
+ return false;
1006
+ }
1007
+ })();
1008
+ if (isCrossOrigin) {
1009
+ const entries = performance.getEntriesByName(url, "resource");
1010
+ if (entries.length > 0) {
1011
+ const last = entries[entries.length - 1];
1012
+ possiblyCors = "responseStatus" in last && last.responseStatus === 0;
1013
+ }
1014
+ }
1015
+ } catch {
1016
+ }
1017
+ }
999
1018
  if (this.logger) {
1000
- if (isCORSError) {
1001
- this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
1002
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
1003
- this.logger.error(` \u2192 Configure security_domains parameter on the server`);
1004
- } else {
1005
- this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
1006
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
1019
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
1020
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
1021
+ if (possiblyCors) {
1022
+ this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
1007
1023
  }
1008
1024
  }
1009
1025
  if (typeof window !== "undefined") {
1010
1026
  try {
1011
- if (isCORSError) {
1012
- window.dispatchEvent(new CustomEvent("cors-error", {
1013
- detail: {
1014
- url,
1015
- method,
1016
- error: error instanceof Error ? error.message : String(error),
1017
- timestamp: /* @__PURE__ */ new Date()
1018
- },
1019
- bubbles: true,
1020
- cancelable: false
1021
- }));
1022
- } else {
1023
- window.dispatchEvent(new CustomEvent("network-error", {
1024
- detail: {
1025
- url,
1026
- method,
1027
- error: error instanceof Error ? error.message : String(error),
1028
- timestamp: /* @__PURE__ */ new Date()
1029
- },
1030
- bubbles: true,
1031
- cancelable: false
1032
- }));
1033
- }
1034
- } catch (eventError) {
1027
+ window.dispatchEvent(new CustomEvent("network-error", {
1028
+ detail: {
1029
+ url,
1030
+ method,
1031
+ error: error instanceof Error ? error.message : String(error),
1032
+ possibly_cors: possiblyCors,
1033
+ timestamp: /* @__PURE__ */ new Date()
1034
+ },
1035
+ bubbles: true,
1036
+ cancelable: false
1037
+ }));
1038
+ } catch {
1035
1039
  }
1036
1040
  }
1037
1041
  const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
@@ -1360,7 +1364,7 @@ __name(sendBatch, "sendBatch");
1360
1364
  // src/client/utils/env.ts
1361
1365
  var isDevelopment = true;
1362
1366
  var isProduction = false;
1363
- var MONITOR_VERSION = "2.1.231";
1367
+ var MONITOR_VERSION = "2.1.233";
1364
1368
 
1365
1369
  // src/client/store/index.ts
1366
1370
  var CIRCUIT_BREAKER_THRESHOLD = 3;