Skip to content

Commit

Permalink
Update Lens embeddable to handle errors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic committed Oct 14, 2022
1 parent 7baeb0f commit be121b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
24 changes: 22 additions & 2 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,25 @@ export class Embeddable
}
}

private getError(): Error | undefined {
const message =
typeof this.errors?.[0]?.longMessage === 'string'
? this.errors[0].longMessage
: this.errors?.[0]?.shortMessage;

if (message != null) {
return new Error(message);
}

if (!this.expression) {
return new Error(
i18n.translate('xpack.lens.embeddable.failure', {
defaultMessage: "Visualization couldn't be displayed",
})
);
}
}

/**
*
* @param {HTMLElement} domNode
Expand All @@ -651,7 +670,7 @@ export class Embeddable
this.updateOutput({
...this.getOutput(),
loading: true,
error: undefined,
error: this.getError(),
});
this.renderComplete.dispatchInProgress();

Expand Down Expand Up @@ -682,7 +701,8 @@ export class Embeddable
style={input.style}
executionContext={this.getExecutionContext()}
canEdit={this.getIsEditable() && input.viewMode === 'edit'}
onRuntimeError={() => {
onRuntimeError={(message) => {
this.updateOutput({ error: new Error(message) });
this.logError('runtime');
}}
noPadding={this.visDisplayOptions?.noPadding}
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/lens/public/embeddable/expression_wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ExpressionWrapperProps {
style?: React.CSSProperties;
className?: string;
canEdit: boolean;
onRuntimeError: () => void;
onRuntimeError: (message?: string) => void;
executionContext?: KibanaExecutionContext;
lensInspector: LensInspector;
noPadding?: boolean;
Expand Down Expand Up @@ -145,15 +145,17 @@ export function ExpressionWrapper({
syncTooltips={syncTooltips}
executionContext={executionContext}
renderError={(errorMessage, error) => {
onRuntimeError();
const messages = getOriginalRequestErrorMessages(error);
onRuntimeError(messages[0] ?? errorMessage);

return (
<div data-test-subj="expression-renderer-error">
<EuiFlexGroup direction="column" alignItems="center" justifyContent="center">
<EuiFlexItem>
<EuiIcon type="alert" color="danger" />
</EuiFlexItem>
<EuiFlexItem>
{(getOriginalRequestErrorMessages(error) || [errorMessage]).map((message) => (
{messages.map((message) => (
<EuiText size="s">{message}</EuiText>
))}
</EuiFlexItem>
Expand Down

0 comments on commit be121b7

Please sign in to comment.