@djangocfg/monitor 2.1.359 → 2.1.361

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
@@ -66,6 +66,65 @@ __name(ensureSessionCookie, "ensureSessionCookie");
66
66
  // src/client/store/index.ts
67
67
  import { createStore } from "zustand/vanilla";
68
68
 
69
+ // src/_api/generated/helpers/errors.ts
70
+ var _APIError = class _APIError extends Error {
71
+ constructor(statusCode, statusText, response, url, message) {
72
+ super(message || `HTTP ${statusCode}: ${statusText}`);
73
+ this.statusCode = statusCode;
74
+ this.statusText = statusText;
75
+ this.response = response;
76
+ this.url = url;
77
+ this.name = "APIError";
78
+ }
79
+ get details() {
80
+ if (typeof this.response === "object" && this.response !== null) {
81
+ return this.response;
82
+ }
83
+ return null;
84
+ }
85
+ get fieldErrors() {
86
+ const details = this.details;
87
+ if (!details) return null;
88
+ const fieldErrors = {};
89
+ for (const [key, value] of Object.entries(details)) {
90
+ if (Array.isArray(value)) fieldErrors[key] = value;
91
+ }
92
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
93
+ }
94
+ get errorMessage() {
95
+ const details = this.details;
96
+ if (!details) return this.message;
97
+ if (details.detail) {
98
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
99
+ }
100
+ if (details.error) return String(details.error);
101
+ if (details.message) return String(details.message);
102
+ const fieldErrors = this.fieldErrors;
103
+ if (fieldErrors) {
104
+ const firstField = Object.keys(fieldErrors)[0];
105
+ if (firstField) return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
106
+ }
107
+ return this.message;
108
+ }
109
+ get isValidationError() {
110
+ return this.statusCode === 400;
111
+ }
112
+ get isAuthError() {
113
+ return this.statusCode === 401;
114
+ }
115
+ get isPermissionError() {
116
+ return this.statusCode === 403;
117
+ }
118
+ get isNotFoundError() {
119
+ return this.statusCode === 404;
120
+ }
121
+ get isServerError() {
122
+ return this.statusCode >= 500 && this.statusCode < 600;
123
+ }
124
+ };
125
+ __name(_APIError, "APIError");
126
+ var APIError = _APIError;
127
+
69
128
  // src/_api/generated/helpers/auth.ts
70
129
  var ACCESS_KEY = "cfg.access_token";
71
130
  var REFRESH_KEY = "cfg.refresh_token";
@@ -144,6 +203,7 @@ function defaultBaseUrl() {
144
203
  }
145
204
  __name(defaultBaseUrl, "defaultBaseUrl");
146
205
  function defaultApiKey() {
206
+ if (isBrowser) return null;
147
207
  try {
148
208
  if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
149
209
  return process.env.NEXT_PUBLIC_API_KEY;
@@ -308,6 +368,13 @@ function installAuthOnClient(client2) {
308
368
  request.headers.set("X-Client-Time", (/* @__PURE__ */ new Date()).toISOString());
309
369
  return request;
310
370
  });
371
+ client2.interceptors.error.use((err, res, req) => {
372
+ if (err instanceof APIError) return err;
373
+ const url = req?.url ?? "";
374
+ const status = res?.status ?? 0;
375
+ const statusText = res?.statusText ?? "";
376
+ return new APIError(status, statusText, err, url);
377
+ });
311
378
  client2.interceptors.response.use(async (response, request) => {
312
379
  if (response.status !== 401) return response;
313
380
  if (request.headers.get(RETRY_MARKER)) {
@@ -1382,7 +1449,7 @@ __name(sendBatch, "sendBatch");
1382
1449
  // src/client/utils/env.ts
1383
1450
  var isDevelopment = process.env.NODE_ENV === "development";
1384
1451
  var isProduction = !isDevelopment;
1385
- var MONITOR_VERSION = "2.1.359";
1452
+ var MONITOR_VERSION = "2.1.361";
1386
1453
 
1387
1454
  // src/client/constants.ts
1388
1455
  var MONITOR_INGEST_PATTERN = /cfg\/monitor\/ingest/;