Error Handling: support errors and data in a response (#20169)

This commit is contained in:
Ryan McKinley
2019-11-05 15:20:04 -08:00
committed by GitHub
parent 7a3d1c0e4b
commit 92ab4d80f0
9 changed files with 68 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ import {
MetricFindValue,
TableData,
TimeSeries,
DataQueryError,
} from '@grafana/data';
import { Scenario, TestDataQuery } from './types';
import { getBackendSrv } from 'app/core/services/backend_srv';
@@ -67,6 +68,7 @@ export class TestDataDataSource extends DataSourceApi<TestDataQuery> {
processQueryResult(queries: any, res: any): DataQueryResponse {
const data: TestData[] = [];
let error: DataQueryError | undefined = undefined;
for (const query of queries) {
const results = res.data.results[query.refId];
@@ -81,9 +83,15 @@ export class TestDataDataSource extends DataSourceApi<TestDataQuery> {
for (const series of results.series || []) {
data.push({ target: series.name, datapoints: series.points, refId: query.refId, tags: series.tags });
}
if (results.error) {
error = {
message: results.error,
};
}
}
return { data };
return { data, error };
}
annotationQuery(options: any) {

View File

@@ -480,13 +480,11 @@ class GraphElement {
this.plot = $.plot(this.elem, this.sortedSeries, options);
if (this.ctrl.renderError) {
delete this.ctrl.error;
delete this.ctrl.inspector;
}
} catch (e) {
console.log('flotcharts error', e);
this.ctrl.error = e.message || 'Render Error';
this.ctrl.renderError = true;
this.ctrl.inspector = { error: e };
}
if (incrementRenderCounter) {