Skip to content

Commit dd36884

Browse files
committed
Fixes #12685 - Improve error handling, add error for missing aggregations key. (#12688)
1 parent 1335f26 commit dd36884

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/core_plugins/metrics/public/components/error.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ function ErrorComponent(props) {
55
const { error } = props;
66
let additionalInfo;
77
const type = _.get(error, 'error.caused_by.type');
8+
let reason = _.get(error, 'error.caused_by.reason');
9+
10+
if (!reason) {
11+
reason = _.get(error, 'message');
12+
}
813

914
if (type === 'script_exception') {
1015
const scriptStack = _.get(error, 'error.caused_by.script_stack');
11-
const reason = _.get(error, 'error.caused_by.caused_by.reason');
16+
reason = _.get(error, 'error.caused_by.caused_by.reason');
1217
additionalInfo = (
1318
<div className="metrics_error__additional">
1419
<div className="metrics_error__reason">{ reason }</div>
1520
<div className="metrics_error__stack">{ scriptStack.join('\n')}</div>
1621
</div>
1722
);
18-
} else {
19-
const reason = _.get(error, 'error.caused_by.reason');
23+
} else if (reason) {
2024
additionalInfo = (
2125
<div className="metrics_error__additional">
2226
<div className="metrics_error__reason">{ reason }</div>

src/core_plugins/metrics/server/lib/vis_data/handle_error_response.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ export default panel => error => {
77
} catch (e) {
88
errorResponse = error.response;
99
}
10+
if (!errorResponse) {
11+
errorResponse = {
12+
message: error.message,
13+
stack: error.stack
14+
};
15+
}
1016
result[panel.id] = {
1117
id: panel.id,
1218
statusCode: error.statusCode,
13-
error: errorResponse || error,
19+
error: errorResponse,
1420
series: []
1521
};
1622
return result;

src/core_plugins/metrics/server/lib/vis_data/handle_response_body.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import buildProcessorFunction from './build_processor_function';
22
import processors from './response_processors/series';
3+
import { get } from 'lodash';
34

45
export default function handleResponseBody(panel) {
56
return resp => {
@@ -8,7 +9,13 @@ export default function handleResponseBody(panel) {
89
err.response = JSON.stringify(resp);
910
throw err;
1011
}
11-
const keys = Object.keys(resp.aggregations);
12+
const aggregations = get(resp, 'aggregations');
13+
if (!aggregations) {
14+
const message = `The aggregations key is missing from the response,
15+
check your permissions for this request.`;
16+
throw Error(message);
17+
}
18+
const keys = Object.keys(aggregations);
1219
if (keys.length !== 1) throw Error('There should only be one series per request.');
1320
const seriesId = keys[0];
1421
const series = panel.series.find(s => s.id === seriesId);

0 commit comments

Comments
 (0)