Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12685 - Improve error handling for TSVB #12688

Merged
merged 2 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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