fix(import): surface real error cause in /pages/import instead of generic 400

The two catch blocks in importPage() threw an opaque "Error processing file
content" / "Failed to create imported page" BadRequest, hiding the real cause
from the HTTP response. This made a production 400 regression impossible to
diagnose without server log access, and violated the project convention that
errors must never be swallowed.

Extract `${err.name}: ${err.message}` into both the log (full err object kept
for the stack) and the thrown BadRequestException. Inner processMarkdown/
processHTML rethrowing catches and the EE processDocx/processPdf license
catches are left unchanged.

Local reproduction of the happy-dom 14->20 theory failed (full import chain
+ 22 edge cases pass on happy-dom@20.8.9), so the root cause is still pending
the now-visible reason from a recurring 400. Diagnostic script test-import.tsx
added; backlog doc updated with findings.
This commit is contained in:
vvzvlad
2026-06-19 16:25:12 +03:00
parent d38de4943d
commit 3d03417c73
3 changed files with 246 additions and 6 deletions

View File

@@ -91,9 +91,14 @@ export class ImportService {
);
}
} catch (err) {
const message = 'Error processing file content';
this.logger.error(message, err);
throw new BadRequestException(message);
// Surface the real cause instead of a generic mask, so the failure is
// diagnosable from the HTTP response (project convention: never swallow).
const reason =
err instanceof Error ? `${err.name}: ${err.message}` : String(err);
this.logger.error(`Error processing file content: ${reason}`, err);
throw new BadRequestException(
`Error processing file content: ${reason}`,
);
}
if (!prosemirrorState) {
@@ -129,9 +134,12 @@ export class ImportService {
`Successfully imported "${title}${fileExtension}. ID: ${createdPage.id} - SlugId: ${createdPage.slugId}"`,
);
} catch (err) {
const message = 'Failed to create imported page';
this.logger.error(message, err);
throw new BadRequestException(message);
const reason =
err instanceof Error ? `${err.name}: ${err.message}` : String(err);
this.logger.error(`Failed to create imported page: ${reason}`, err);
throw new BadRequestException(
`Failed to create imported page: ${reason}`,
);
}
}