Skip to content

Commit

Permalink
Import "getPainlessError" function from Kibana
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Ángel committed May 29, 2019
1 parent e41765a commit 43f5dd5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
51 changes: 51 additions & 0 deletions public/kibana-integrations/get_painless_error.ts
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { get } from 'lodash';

export function getPainlessError(error: Error) {
const rootCause: Array<{ lang: string; script: string }> | undefined = get(
error,
'resp.error.root_cause'
);

if (!rootCause) {
return;
}

const [{ lang, script }] = rootCause;

if (lang !== 'painless') {
return;
}

return {
lang,
script,
message: i18n.translate(
'kbn.discover.painlessError.painlessScriptedFieldErrorMessage',
{
defaultMessage: "Error with Painless scripted field '{script}'.",
values: { script }
}
),
error: error.message
};
}
2 changes: 2 additions & 0 deletions public/kibana-integrations/kibana-discover.js
Expand Up @@ -99,6 +99,8 @@ import { buildVislibDimensions } from 'ui/visualize/loader/pipeline_helpers/buil

import 'ui/courier/search_strategy/default_search_strategy';

import { getPainlessError } from './get_painless_error';

const app = uiModules.get('apps/discover', [
'kibana/notify',
'kibana/courier',
Expand Down

0 comments on commit 43f5dd5

Please sign in to comment.