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', {