refactor(utils): add safeExtractMessageAndStackFromError util to remove code duplication

This commit is contained in:
Panagiotis Papadopoulos
2025-03-08 17:07:25 +01:00
parent e20b662ea7
commit ecf1a0e4ad
9 changed files with 44 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ import becca from "../../becca/becca.js";
import syncService from "../../services/sync.js";
import sql from "../../services/sql.js";
import type { Request } from "express";
import { safeExtractMessageAndStackFromError } from "../../services/utils.js";
interface ScriptBody {
script: string;
@@ -34,9 +35,10 @@ async function exec(req: Request) {
maxEntityChangeId: syncService.getMaxEntityChangeId()
};
} catch (e: unknown) {
const [errMessage] = safeExtractMessageAndStackFromError(e);
return {
success: false,
error: (e instanceof Error) ? e.message : "Unknown Error"
error: errMessage
};
}
}