commit 242b965f3baee5bf22fde034db390edec6d53333
parent d1d234dcaeecea8b6a1b0769a3d499b8c07a5269
Author: Sebastian <sebasjm@taler-systems.com>
Date: Thu, 28 May 2026 08:07:46 -0300
build abs dir and put render error handling on webutils
Diffstat:
6 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/packages/web-util/build.mjs b/packages/web-util/build.mjs
@@ -18,11 +18,15 @@
import esbuild from "esbuild";
import path from "node:path";
import fs from "node:fs";
+import nodeUrl from "node:url";
+
+const root = path.dirname(nodeUrl.fileURLToPath(import.meta.url));
+process.chdir(root);
// eslint-disable-next-line no-undef
-const BASE = process.cwd();
+const BASE_DIR = process.cwd();
-let GIT_ROOT = BASE;
+let GIT_ROOT = BASE_DIR;
while (!fs.existsSync(path.join(GIT_ROOT, ".git")) && GIT_ROOT !== "/") {
GIT_ROOT = path.join(GIT_ROOT, "../");
}
@@ -31,7 +35,7 @@ const GIT_HASH = GIT_ROOT === "/" ? 'not defined' : git_hash();
let PACKAGE_VERSION = get_version()
function get_version() {
try {
- return JSON.parse(fs.readFileSync(path.join(BASE, "package.json"))).version;
+ return JSON.parse(fs.readFileSync(path.join(BASE_DIR, "package.json"))).version;
} catch {
return 'not defined'
}
@@ -98,6 +102,7 @@ const nativeNodeModulesPlugin = {
const buildConfigBase = {
outdir: "lib",
+ absWorkingDir: BASE_DIR,
bundle: true,
minify: false,
target: ["es2020"],
diff --git a/packages/web-util/src/context/bank-api.ts b/packages/web-util/src/context/bank-api.ts
@@ -129,12 +129,12 @@ export const BankApiProvider = ({
if (checked === undefined) {
return h(frameOnError, {
- children: h("div", {}, "checking compatibility with server..."),
+ children: h("div", {}, i18n.str`Checking compatibility of this webapp with backend service...`),
});
}
if (checked.type === "error") {
return h(frameOnError, {
- children: h(ErrorLoading, { error: checked.error }),
+ children: h(ErrorLoading, { title: i18n.str`There was an error trying to contact the backend service.`, error: checked.error }),
});
}
if (checked.type === "incompatible") {
diff --git a/packages/web-util/src/context/challenger-api.ts b/packages/web-util/src/context/challenger-api.ts
@@ -131,12 +131,12 @@ export const ChallengerApiProvider = ({
if (checked === undefined) {
return h(frameOnError, {
- children: h("div", {}, "checking compatibility with server..."),
+ children: h("div", {}, i18n.str`Checking compatibility of this webapp with backend service...`),
});
}
if (checked.type === "error") {
return h(frameOnError, {
- children: h(ErrorLoading, { error: checked.error }),
+ children: h(ErrorLoading, { title: i18n.str`There was an error trying to contact the backend service.`, error: checked.error }),
});
}
if (checked.type === "incompatible") {
diff --git a/packages/web-util/src/context/exchange-api.ts b/packages/web-util/src/context/exchange-api.ts
@@ -153,12 +153,12 @@ export const ExchangeApiProvider = ({
if (checked === undefined) {
return h(frameOnError, {
- children: h("div", {}, "checking compatibility with server..."),
+ children: h("div", {}, i18n.str`Checking compatibility of this webapp with backend service...`),
});
}
if (checked.type === "error") {
return h(frameOnError, {
- children: h(ErrorLoading, { error: checked.error }),
+ children: h(ErrorLoading, { title: i18n.str`There was an error trying to contact the backend service.`, error: checked.error }),
});
}
if (checked.type === "incompatible") {
diff --git a/packages/web-util/src/hooks/errors.ts b/packages/web-util/src/hooks/errors.ts
@@ -0,0 +1,37 @@
+import { useEffect, useErrorBoundary } from "preact/hooks";
+import { useTranslationContext } from "../context/translation.js";
+
+export function useRenderErrorReport() {
+ const { i18n } = useTranslationContext();
+ const [error] = useErrorBoundary();
+
+ useEffect(() => {
+ if (error) {
+ if (error instanceof Error) {
+ // notifyException(i18n.str`Internal error, please report.`, error);
+ } else {
+ // notifyError(
+ // i18n.str`Internal error, please report.`,
+ // String(error) as TranslatedString,
+ // );
+ }
+ console.log(error);
+ }
+ }, [error]);
+}
+
+// useEffect(() => {
+// if (error) {
+// if (error instanceof Error) {
+// console.log("Internal error, please report", error);
+// notifyException(i18n.str`Internal error, please report.`, error);
+// } else {
+// console.log("Internal error, please report", error);
+// notifyError(
+// i18n.str`Internal error, please report.`,
+// String(error) as TranslatedString,
+// );
+// }
+// resetError();
+// }
+// }, [error]);
diff --git a/packages/web-util/src/hooks/index.ts b/packages/web-util/src/hooks/index.ts
@@ -16,6 +16,7 @@ export {
useForm,
useFormMeta,
} from "./useForm.js";
+export { useRenderErrorReport } from "./errors.js";
export { useLang } from "./useLang.js";
export { useChallengeHandler, MfaHandler, MfaState } from "./useChallenge.js";
export {