PanelQueryRunner: move error handling to QueryRunnerOptions (#16654)

This commit is contained in:
Ryan McKinley 2019-04-17 12:05:58 -07:00 committed by Torkel Ödegaard
parent ed0192104c
commit f4cd9bc73c
2 changed files with 17 additions and 13 deletions

View File

@ -99,15 +99,9 @@ export class PanelChrome extends PureComponent<Props, State> {
if (data.state === LoadingState.Error) {
const { error } = data;
if (error) {
let message = 'Query error';
if (error.message) {
message = error.message;
} else if (error.data && error.data.message) {
message = error.data.message;
} else if (error.data && error.data.error) {
message = error.data.error;
} else if (error.status) {
message = `Query error: ${error.status} ${error.statusText}`;
let message = error.message;
if (!message) {
message = 'Query error';
}
if (this.state.errorMessage !== message) {

View File

@ -20,10 +20,10 @@ import cloneDeep from 'lodash/cloneDeep';
import kbn from 'app/core/utils/kbn';
export interface QueryRunnerOptions {
ds?: DataSourceApi; // if they already have the datasource, don't look it up
export interface QueryRunnerOptions<TQuery extends DataQuery = DataQuery> {
ds?: DataSourceApi<TQuery>; // if they already have the datasource, don't look it up
datasource: string | null;
queries: DataQuery[];
queries: TQuery[];
panelId: number;
dashboardId?: number;
timezone?: string;
@ -174,7 +174,17 @@ export class PanelQueryRunner {
} catch (err) {
const error = err as DataQueryError;
if (!error.message) {
err.message = 'Query Error';
let message = 'Query error';
if (error.message) {
message = error.message;
} else if (error.data && error.data.message) {
message = error.data.message;
} else if (error.data && error.data.error) {
message = error.data.error;
} else if (error.status) {
message = `Query error: ${error.status} ${error.statusText}`;
}
error.message = message;
}
this.data = {