diff --git a/src/core_plugins/metrics/public/components/error.js b/src/core_plugins/metrics/public/components/error.js
index deafa04eb1b6d..a88477eb5b25c 100644
--- a/src/core_plugins/metrics/public/components/error.js
+++ b/src/core_plugins/metrics/public/components/error.js
@@ -5,18 +5,22 @@ function ErrorComponent(props) {
const { error } = props;
let additionalInfo;
const type = _.get(error, 'error.caused_by.type');
+ let reason = _.get(error, 'error.caused_by.reason');
+
+ if (!reason) {
+ reason = _.get(error, 'message');
+ }
if (type === 'script_exception') {
const scriptStack = _.get(error, 'error.caused_by.script_stack');
- const reason = _.get(error, 'error.caused_by.caused_by.reason');
+ reason = _.get(error, 'error.caused_by.caused_by.reason');
additionalInfo = (
{ reason }
{ scriptStack.join('\n')}
);
- } else {
- const reason = _.get(error, 'error.caused_by.reason');
+ } else if (reason) {
additionalInfo = (
{ reason }
diff --git a/src/core_plugins/metrics/server/lib/vis_data/handle_error_response.js b/src/core_plugins/metrics/server/lib/vis_data/handle_error_response.js
index 6a8a8d1c08c1b..f322277d74b93 100644
--- a/src/core_plugins/metrics/server/lib/vis_data/handle_error_response.js
+++ b/src/core_plugins/metrics/server/lib/vis_data/handle_error_response.js
@@ -7,10 +7,16 @@ export default panel => error => {
} catch (e) {
errorResponse = error.response;
}
+ if (!errorResponse) {
+ errorResponse = {
+ message: error.message,
+ stack: error.stack
+ };
+ }
result[panel.id] = {
id: panel.id,
statusCode: error.statusCode,
- error: errorResponse || error,
+ error: errorResponse,
series: []
};
return result;
diff --git a/src/core_plugins/metrics/server/lib/vis_data/handle_response_body.js b/src/core_plugins/metrics/server/lib/vis_data/handle_response_body.js
index a2d531bed213d..e08b265560f80 100644
--- a/src/core_plugins/metrics/server/lib/vis_data/handle_response_body.js
+++ b/src/core_plugins/metrics/server/lib/vis_data/handle_response_body.js
@@ -1,5 +1,6 @@
import buildProcessorFunction from './build_processor_function';
import processors from './response_processors/series';
+import { get } from 'lodash';
export default function handleResponseBody(panel) {
return resp => {
@@ -8,7 +9,13 @@ export default function handleResponseBody(panel) {
err.response = JSON.stringify(resp);
throw err;
}
- const keys = Object.keys(resp.aggregations);
+ const aggregations = get(resp, 'aggregations');
+ if (!aggregations) {
+ const message = `The aggregations key is missing from the response,
+ check your permissions for this request.`;
+ throw Error(message);
+ }
+ const keys = Object.keys(aggregations);
if (keys.length !== 1) throw Error('There should only be one series per request.');
const seriesId = keys[0];
const series = panel.series.find(s => s.id === seriesId);