mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Error Handling: support errors and data in a response (#20169)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user