refactor(clickTtPlayerRegistrationService): enhance error diagnostics and HTML file handling

- Added directory creation for debug HTML file paths to ensure proper file generation during error handling.
- Improved diagnostics object to capture additional error context, including URL and sanitized body text, enhancing troubleshooting capabilities.
- Streamlined error handling to maintain partial diagnostics even when certain data retrieval fails, improving robustness in error reporting.
This commit is contained in:
Torsten Schulz (local)
2026-03-11 17:04:49 +01:00
parent a77926838b
commit ab466adde7

View File

@@ -1,5 +1,5 @@
import { chromium } from 'playwright';
import { writeFile } from 'fs/promises';
import { mkdir, writeFile } from 'fs/promises';
import path from 'path';
import Member from '../models/Member.js';
import Club from '../models/Club.js';
@@ -140,22 +140,36 @@ class ClickTtPlayerRegistrationService {
trace
};
} catch (error) {
let diagnostics = {};
const diagnostics = {
url: null,
text: null,
traceTail: trace.slice(-25),
htmlPath: null
};
try {
const html = await page?.content?.();
const htmlPath = html ? buildDebugHtmlPath() : null;
if (html && htmlPath) {
await mkdir(path.dirname(htmlPath), { recursive: true });
await writeFile(htmlPath, html, 'utf8');
diagnostics.htmlPath = htmlPath;
}
diagnostics = {
url: page?.url?.() || null,
text: sanitizePageText(await page?.locator?.('body')?.innerText?.()),
traceTail: trace.slice(-25),
htmlPath
};
} catch (_err) {
diagnostics = {};
// keep partial diagnostics
}
try {
diagnostics.url = page?.url?.() || null;
} catch (_err) {
// ignore
}
try {
const bodyText = await page?.locator?.('body')?.innerText?.();
diagnostics.text = sanitizePageText(bodyText);
} catch (_err) {
// ignore
}
this._trace(trace, 'error', {