@scalio-cloud/ui 0.44.1 → 0.45.0
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 +13 -0
- package/package.json +1 -1
- package/react/clientErrors.js +61 -0
- package/react/index.js +1 -1
package/README.md
CHANGED
|
@@ -104,6 +104,19 @@ export const { AuthProvider, useAuth } = createAuth({ api, formatError: formatAp
|
|
|
104
104
|
passkeyCancelled, legacyTokenKey: "pulse_token" });
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
## Browser-Fehler an Scalio Monitor (React-frei, from 0.45.0)
|
|
108
|
+
|
|
109
|
+
`reportClientErrors({ post, max })` hört auf `error` und `unhandledrejection` des Fensters und schickt jeden Fehler
|
|
110
|
+
einmal (höchstens `max`, Standard 10 pro Seitenaufruf) über das eigene Backend: `POST /api/client-errors` aus
|
|
111
|
+
scalio-platform 0.23.0 (`error_report.client_errors_router(require_user)`), nie direkt an den Monitor. Gesendet
|
|
112
|
+
werden nur Typ, Meldung, Stack und der Pfad ohne Query und Hash; Fehler von Browser-Erweiterungen und der harmlose
|
|
113
|
+
ResizeObserver-Hinweis bleiben weg. Gibt eine Funktion zurück, die das Zuhören beendet.
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { reportClientErrors } from "@scalio-cloud/ui/react";
|
|
117
|
+
reportClientErrors({ post: (body) => api.post("/client-errors", body) }); // einmal in main.jsx
|
|
118
|
+
```
|
|
119
|
+
|
|
107
120
|
## App header (React)
|
|
108
121
|
|
|
109
122
|
Every app shows the same header on the right, always in this order: (app actions), status, language, theme,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Browser errors to Scalio Monitor through the app's own backend (scalio-platform 0.23.0
|
|
3
|
+
// error_report.client_errors_router, POST /api/client-errors; never straight to the monitor, concept monitoring.md).
|
|
4
|
+
// reportClientErrors({ post, max }) listens to window "error" and "unhandledrejection" and returns a function that
|
|
5
|
+
// stops it. post(body) is the app's call, e.g. (b) => api.post("/client-errors", b). Sent: type, message, stack
|
|
6
|
+
// and the page path (no query, no hash). Each error once per page load, at most `max` (10) in all; errors of
|
|
7
|
+
// browser extensions and the harmless ResizeObserver notice are left out. A failing post is ignored.
|
|
8
|
+
const NOISE = [/ResizeObserver loop/i, /^Script error\.?$/i];
|
|
9
|
+
const EXTENSION = /(chrome|moz|safari(-web)?)-extension:\/\//i;
|
|
10
|
+
|
|
11
|
+
function describe(reason) {
|
|
12
|
+
if (reason && typeof reason === "object") {
|
|
13
|
+
return {
|
|
14
|
+
type: String(reason.name || (reason.constructor && reason.constructor.name) || "Error").slice(0, 120),
|
|
15
|
+
message: String(reason.message || "").slice(0, 1000),
|
|
16
|
+
stack: String(reason.stack || "").slice(0, 4000),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { type: "Error", message: String(reason == null ? "" : reason).slice(0, 1000), stack: "" };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clientErrorBody(reason, win) {
|
|
23
|
+
const body = describe(reason);
|
|
24
|
+
const loc = (win && win.location) || {};
|
|
25
|
+
body.path = String(loc.pathname || "").slice(0, 300);
|
|
26
|
+
return body;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function reportClientErrors(opts) {
|
|
30
|
+
const o = opts || {};
|
|
31
|
+
const win = o.window || (typeof window !== "undefined" ? window : null);
|
|
32
|
+
if (!win || typeof o.post !== "function") return () => {};
|
|
33
|
+
const max = o.max || 10;
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
let sent = 0;
|
|
36
|
+
|
|
37
|
+
const send = (reason) => {
|
|
38
|
+
const body = clientErrorBody(reason, win);
|
|
39
|
+
if (!body.message && !body.stack) return;
|
|
40
|
+
if (NOISE.some((re) => re.test(body.message)) || EXTENSION.test(body.stack)) return;
|
|
41
|
+
const key = `${body.type}|${body.message}`;
|
|
42
|
+
if (seen.has(key) || sent >= max) return;
|
|
43
|
+
seen.add(key);
|
|
44
|
+
sent += 1;
|
|
45
|
+
try {
|
|
46
|
+
Promise.resolve(o.post(body)).catch(() => {});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
/* reporting never breaks the page */
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const onError = (ev) => send(ev && (ev.error || ev.message));
|
|
52
|
+
const onRejection = (ev) => send(ev && ev.reason);
|
|
53
|
+
win.addEventListener("error", onError);
|
|
54
|
+
win.addEventListener("unhandledrejection", onRejection);
|
|
55
|
+
return () => {
|
|
56
|
+
win.removeEventListener("error", onError);
|
|
57
|
+
win.removeEventListener("unhandledrejection", onRejection);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { reportClientErrors, clientErrorBody };
|
package/react/index.js
CHANGED
|
@@ -380,4 +380,4 @@ module.exports = {
|
|
|
380
380
|
};
|
|
381
381
|
Object.assign(module.exports, Nav, Blocks, require("./settings"), require("./support"), require("./beacon"), require("./security"), require("./license"), require("./palette"), require("./unify"), require("./profile"), require("./actions"), require("./selftest"), require("./users"), require("./customers"), require("./roles"), require("./wizard"), require("./maintenance"), require("./backup"), require("./audit"), require("./mail"), require("./saas_updates"), require("./pages"), require("./tenant"), require("./fields"));
|
|
382
382
|
// After the exports above: auth.js uses LanguageToggle and ThemeToggle from this module.
|
|
383
|
-
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"));
|
|
383
|
+
Object.assign(module.exports, require("./auth"), require("./session"), require("./setup"), require("./clientErrors"));
|