mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Lens] Expose ES errors in workspace (#94606)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
fc45b2007c
commit
6479e410d7
2 changed files with 27 additions and 3 deletions
|
@ -27,7 +27,7 @@ export function TableDimensionEditor(
|
|||
const currentAlignment =
|
||||
column?.alignment ||
|
||||
(frame.activeData &&
|
||||
frame.activeData[state.layerId].columns.find(
|
||||
frame.activeData[state.layerId]?.columns.find(
|
||||
(col) => col.id === accessor || getOriginalId(col.id) === accessor
|
||||
)?.meta.type === 'number'
|
||||
? 'right'
|
||||
|
|
|
@ -26,6 +26,17 @@ const isRequestError = (e: Error | RequestError): e is RequestError => {
|
|||
return false;
|
||||
};
|
||||
|
||||
interface ESError extends Error {
|
||||
attributes?: { caused_by?: ElasticsearchErrorClause };
|
||||
}
|
||||
|
||||
const isEsError = (e: Error | ESError): e is ESError => {
|
||||
if ('attributes' in e) {
|
||||
return e.attributes?.caused_by?.caused_by !== undefined;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
function getNestedErrorClause({
|
||||
type,
|
||||
reason,
|
||||
|
@ -37,9 +48,22 @@ function getNestedErrorClause({
|
|||
return { type, reason };
|
||||
}
|
||||
|
||||
function getErrorSource(e: Error | RequestError | ESError) {
|
||||
if (isRequestError(e)) {
|
||||
return e.body!.attributes!.error;
|
||||
}
|
||||
if (isEsError(e)) {
|
||||
return e.attributes!.caused_by;
|
||||
}
|
||||
}
|
||||
|
||||
export function getOriginalRequestErrorMessage(error?: ExpressionRenderError | null) {
|
||||
if (error && 'original' in error && error.original && isRequestError(error.original)) {
|
||||
const rootError = getNestedErrorClause(error.original.body!.attributes!.error);
|
||||
if (error && 'original' in error && error.original) {
|
||||
const errorSource = getErrorSource(error.original);
|
||||
if (errorSource == null) {
|
||||
return;
|
||||
}
|
||||
const rootError = getNestedErrorClause(errorSource);
|
||||
if (rootError.reason && rootError.type) {
|
||||
return i18n.translate('xpack.lens.editorFrame.expressionFailureMessage', {
|
||||
defaultMessage: 'Request error: {type}, {reason}',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue