@panomc/theme-core 1.0.0-dev.66 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.0.0-dev.66",
3
+ "version": "1.0.0",
4
4
  "description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
5
5
  "author": "PanoMC",
6
6
  "pano": {
@@ -61,7 +61,7 @@
61
61
  "@fortawesome/fontawesome-free": "^6.7.2"
62
62
  },
63
63
  "peerDependencies": {
64
- "@panomc/sdk": "^2.0.0-dev.66",
64
+ "@panomc/sdk": "^2.0.0",
65
65
  "@sveltejs/adapter-node": "^6.0.0",
66
66
  "@sveltejs/kit": "^3.1.0",
67
67
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
@@ -71,7 +71,7 @@
71
71
  "vite": "^8.3.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@panomc/sdk": "2.0.0-dev.66",
74
+ "@panomc/sdk": "2.0.0",
75
75
  "@sveltejs/adapter-node": "^6.0.0",
76
76
  "@sveltejs/kit": "^3.1.0",
77
77
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
@@ -54,3 +54,34 @@ describe("handleFetch", () => {
54
54
  expect(sent.headers.get("cookie")).toBe("a=b");
55
55
  });
56
56
  });
57
+
58
+ describe("handleError", () => {
59
+ const event = { url: new URL("http://127.0.0.1:3000/ticket/2") };
60
+
61
+ const logged = (run) => {
62
+ const log = console.log;
63
+ const errorLog = console.error;
64
+ const calls = [];
65
+ console.log = (...args) => calls.push(args);
66
+ console.error = (...args) => calls.push(args);
67
+ try {
68
+ run();
69
+ } finally {
70
+ console.log = log;
71
+ console.error = errorLog;
72
+ }
73
+ return calls.length;
74
+ };
75
+
76
+ test("a 404 from a load is not logged as a server error", () => {
77
+ const { handleError } = createThemeHooks({ internalLibsHash: "x", runtimeShimsHash: "x", suppressNoisyErrors: false });
78
+
79
+ expect(logged(() => handleError({ error: { status: 404, message: "NOT_EXISTS" }, event, status: 404 }))).toBe(0);
80
+ });
81
+
82
+ test("an unexpected error is still logged", () => {
83
+ const { handleError } = createThemeHooks({ internalLibsHash: "x", runtimeShimsHash: "x", suppressNoisyErrors: false });
84
+
85
+ expect(logged(() => handleError({ error: new Error("boom"), event, status: 500 }))).toBe(2);
86
+ });
87
+ });
@@ -46,6 +46,18 @@ function getCookieWithHttpFallback(cookies, baseName) {
46
46
  }
47
47
 
48
48
  /** In production, skip logging common client/bot noise (wrong method, stray POST to non-action routes). */
49
+ /**
50
+ * Whether [status] is a client error (400-499): an expected answer such as a 404, not a failure.
51
+ *
52
+ * @param {unknown} status
53
+ * @returns {boolean}
54
+ */
55
+ export function isClientErrorStatus(status) {
56
+ const code = Number(status);
57
+
58
+ return Number.isInteger(code) && code >= 400 && code < 500;
59
+ }
60
+
49
61
  function shouldSuppressServerErrorLog(error) {
50
62
  if (process.env.NODE_ENV !== "production") return false;
51
63
  if (error?.status === 405) return true;
@@ -323,8 +335,12 @@ ${importMapEntries}
323
335
  }
324
336
 
325
337
  /** @type {import('@sveltejs/kit').HandleServerError} */
326
- function handleError({ error, event }) {
327
- if (!suppressNoisyErrors || !shouldSuppressServerErrorLog(error)) {
338
+ function handleError({ error, event, status }) {
339
+ // A 4xx (a missing ticket, page or post: `error(404, "NOT_EXISTS")`) is an answer, not a fault
340
+ // of this server, so it is never logged; only what ends in a 5xx is.
341
+ const failed = !isClientErrorStatus(status ?? error?.status);
342
+
343
+ if (failed && (!suppressNoisyErrors || !shouldSuppressServerErrorLog(error))) {
328
344
  console.log("!!! [GLOBAL ERROR EVENT]:", event.url.href);
329
345
  console.error("!!! [GLOBAL ERROR CONTENT]:", error);
330
346
  }