@djangocfg/monitor 2.1.358 → 2.1.360

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.cjs CHANGED
@@ -100,6 +100,65 @@ __name(ensureSessionCookie, "ensureSessionCookie");
100
100
  // src/client/store/index.ts
101
101
  var import_vanilla = require("zustand/vanilla");
102
102
 
103
+ // src/_api/generated/helpers/errors.ts
104
+ var _APIError = class _APIError extends Error {
105
+ constructor(statusCode, statusText, response, url, message) {
106
+ super(message || `HTTP ${statusCode}: ${statusText}`);
107
+ this.statusCode = statusCode;
108
+ this.statusText = statusText;
109
+ this.response = response;
110
+ this.url = url;
111
+ this.name = "APIError";
112
+ }
113
+ get details() {
114
+ if (typeof this.response === "object" && this.response !== null) {
115
+ return this.response;
116
+ }
117
+ return null;
118
+ }
119
+ get fieldErrors() {
120
+ const details = this.details;
121
+ if (!details) return null;
122
+ const fieldErrors = {};
123
+ for (const [key, value] of Object.entries(details)) {
124
+ if (Array.isArray(value)) fieldErrors[key] = value;
125
+ }
126
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
127
+ }
128
+ get errorMessage() {
129
+ const details = this.details;
130
+ if (!details) return this.message;
131
+ if (details.detail) {
132
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
133
+ }
134
+ if (details.error) return String(details.error);
135
+ if (details.message) return String(details.message);
136
+ const fieldErrors = this.fieldErrors;
137
+ if (fieldErrors) {
138
+ const firstField = Object.keys(fieldErrors)[0];
139
+ if (firstField) return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
140
+ }
141
+ return this.message;
142
+ }
143
+ get isValidationError() {
144
+ return this.statusCode === 400;
145
+ }
146
+ get isAuthError() {
147
+ return this.statusCode === 401;
148
+ }
149
+ get isPermissionError() {
150
+ return this.statusCode === 403;
151
+ }
152
+ get isNotFoundError() {
153
+ return this.statusCode === 404;
154
+ }
155
+ get isServerError() {
156
+ return this.statusCode >= 500 && this.statusCode < 600;
157
+ }
158
+ };
159
+ __name(_APIError, "APIError");
160
+ var APIError = _APIError;
161
+
103
162
  // src/_api/generated/helpers/auth.ts
104
163
  var ACCESS_KEY = "cfg.access_token";
105
164
  var REFRESH_KEY = "cfg.refresh_token";
@@ -342,6 +401,13 @@ function installAuthOnClient(client2) {
342
401
  request.headers.set("X-Client-Time", (/* @__PURE__ */ new Date()).toISOString());
343
402
  return request;
344
403
  });
404
+ client2.interceptors.error.use((err, res, req) => {
405
+ if (err instanceof APIError) return err;
406
+ const url = req?.url ?? "";
407
+ const status = res?.status ?? 0;
408
+ const statusText = res?.statusText ?? "";
409
+ return new APIError(status, statusText, err, url);
410
+ });
345
411
  client2.interceptors.response.use(async (response, request) => {
346
412
  if (response.status !== 401) return response;
347
413
  if (request.headers.get(RETRY_MARKER)) {
@@ -1416,7 +1482,7 @@ __name(sendBatch, "sendBatch");
1416
1482
  // src/client/utils/env.ts
1417
1483
  var isDevelopment = process.env.NODE_ENV === "development";
1418
1484
  var isProduction = !isDevelopment;
1419
- var MONITOR_VERSION = "2.1.358";
1485
+ var MONITOR_VERSION = "2.1.360";
1420
1486
 
1421
1487
  // src/client/constants.ts
1422
1488
  var MONITOR_INGEST_PATTERN = /cfg\/monitor\/ingest/;