[Lens] Expose ES errors in workspace (#94606)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marco Liberati 2021-03-17 14:26:43 +01:00 committed by GitHub
parent fc45b2007c
commit 6479e410d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

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

View file

@ -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}',