[Reporting] Refactor error messages with human-friendly version of message (#136501)

* refactor error code messages with new method specifically for human-friendly version of errors

* update error copy

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2022-07-22 11:27:16 +02:00 committed by GitHub
parent d16a4d8bd9
commit af3a3cba9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 29 deletions

View file

@ -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.`,
});
}
}

View file

@ -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;