diff --git a/x-pack/plugins/reporting/common/errors/index.ts b/x-pack/plugins/reporting/common/errors/index.ts index 9da4173aef91f..3a027ce8d29a0 100644 --- a/x-pack/plugins/reporting/common/errors/index.ts +++ b/x-pack/plugins/reporting/common/errors/index.ts @@ -8,6 +8,12 @@ /* eslint-disable max-classes-per-file */ import { i18n } from '@kbn/i18n'; +export interface ReportingError { + /** + * Return a message describing the error that is human friendly + */ + humanFriendlyMessage?(): string; +} export abstract class ReportingError extends Error { /** * A string that uniquely brands an error type. This is used to power telemetry @@ -87,17 +93,10 @@ export class PdfWorkerOutOfMemoryError extends ReportingError { return PdfWorkerOutOfMemoryError.code; } - details = i18n.translate('xpack.reporting.common.pdfWorkerOutOfMemoryErrorMessage', { - defaultMessage: - 'Cannot generate PDF due to low memory. Consider making a smaller PDF before retrying this report.', - }); - - /** - * No need to provide extra details, we know exactly what happened and can provide - * a nicely formatted message - */ - public override get message(): string { - return this.details; + public humanFriendlyMessage() { + return i18n.translate('xpack.reporting.common.pdfWorkerOutOfMemoryErrorMessage', { + defaultMessage: `Can't generate a PDF due to insufficient memory. Try making a smaller PDF and retrying this report.`, + }); } } @@ -107,16 +106,10 @@ export class BrowserCouldNotLaunchError extends ReportingError { return BrowserCouldNotLaunchError.code; } - details = i18n.translate('xpack.reporting.common.browserCouldNotLaunchErrorMessage', { - defaultMessage: 'Cannot generate screenshots because the browser did not launch.', - }); - - /** - * For this error message we expect that users will use the diagnostics - * functionality in reporting to debug further. - */ - public override get message() { - return this.details; + public humanFriendlyMessage() { + return i18n.translate('xpack.reporting.common.browserCouldNotLaunchErrorMessage', { + defaultMessage: `Can't generate screenshots because the browser did not launch. See the server logs for more information.`, + }); } } @@ -151,12 +144,9 @@ export class VisualReportingSoftDisabledError extends ReportingError { return VisualReportingSoftDisabledError.code; } - details = i18n.translate('xpack.reporting.common.cloud.insufficientSystemMemoryError', { - defaultMessage: - 'This report cannot be generated because Kibana does not have sufficient memory.', - }); - - public override get message() { - return this.details; + humanFriendlyMessage() { + return i18n.translate('xpack.reporting.common.cloud.insufficientSystemMemoryError', { + defaultMessage: `Can't generate this report due to insufficient memory.`, + }); } } diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index 73dc29801ac0d..ca3ba4445f940 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -232,7 +232,7 @@ export class ExecuteReportTask implements ReportingTask { docOutput.error_code = output.error_code; } else { const defaultOutput = null; - docOutput.content = output.toString() || defaultOutput; + docOutput.content = output.humanFriendlyMessage?.() || output.toString() || defaultOutput; docOutput.content_type = unknownMime; docOutput.warnings = [output.toString()]; docOutput.error_code = output.code;