Skip to content

Commit 19debfa

Browse files
authored
Improve health check by returning errors properly (#327)
1 parent 3bb5922 commit 19debfa

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.changeset/unlucky-avocados-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-bigquery-datasource': patch
3+
---
4+
5+
Improve health check by returning errors properly

src/datasource.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@grafana/data';
88
import { EditorMode } from '@grafana/plugin-ui';
99
import { GoogleAuthType } from '@grafana/google-sdk';
10-
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
10+
import { DataSourceWithBackend, getTemplateSrv, HealthCheckError } from '@grafana/runtime';
1111
import { getApiClient } from 'api';
1212
import { uniqueId } from 'lodash';
1313
import { VariableEditor } from './components/VariableEditor';
@@ -81,18 +81,22 @@ export class BigQueryDatasource extends DataSourceWithBackend<BigQueryQueryNG, B
8181
async testDatasource() {
8282
const health = await this.callHealthCheck();
8383
if (health.status?.toLowerCase() === 'error') {
84-
return { status: 'error', message: health.message, details: health.details };
84+
return Promise.reject({
85+
status: 'error',
86+
message: health.message,
87+
error: new HealthCheckError(health.message, health.details),
88+
});
8589
}
8690

8791
const client = await getApiClient(this.id);
8892
try {
8993
await client.getProjects();
9094
} catch (err: any) {
91-
return {
95+
return Promise.reject({
9296
status: 'error',
9397
message: err.data?.message || 'Error connecting to resource manager.',
94-
details: err.data?.details,
95-
};
98+
error: new HealthCheckError(err.data?.message, err.data?.details),
99+
});
96100
}
97101
return {
98102
status: 'OK',

0 commit comments

Comments
 (0)