From ab466adde79eec27c794db62983270956f367359 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 11 Mar 2026 17:04:49 +0100 Subject: [PATCH] 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. --- .../clickTtPlayerRegistrationService.js | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/backend/services/clickTtPlayerRegistrationService.js b/backend/services/clickTtPlayerRegistrationService.js index 5685f7b8..510a7ba5 100644 --- a/backend/services/clickTtPlayerRegistrationService.js +++ b/backend/services/clickTtPlayerRegistrationService.js @@ -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', {