Skip to content

Commit

Permalink
Fixes #12685 - Improve error handling, add error for missing aggregat…
Browse files Browse the repository at this point in the history
…ions key. (#12688)
  • Loading branch information
simianhacker authored Aug 10, 2017
1 parent 3a07e5c commit 805c15c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/core_plugins/metrics/public/components/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<div className="metrics_error__additional">
<div className="metrics_error__reason">{ reason }</div>
<div className="metrics_error__stack">{ scriptStack.join('\n')}</div>
</div>
);
} else {
const reason = _.get(error, 'error.caused_by.reason');
} else if (reason) {
additionalInfo = (
<div className="metrics_error__additional">
<div className="metrics_error__reason">{ reason }</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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);
Expand Down

0 comments on commit 805c15c

Please sign in to comment.