SQL: Fix issue where testing the datasource would always be successful if the `datasourceQueryMultiStatus` feature was enabled (#58671)

SQL Datasources: fix issue where testing the datasource connection would show success even when there was an error.

Co-authored-by: Victor Marin <victor.marin@grafana.com>
pull/58686/head
Oscar Kilhed 3 years ago committed by GitHub
parent 6e776d0fec
commit 75e435fb00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      public/app/features/plugins/sql/datasource/SqlDatasource.ts

@ -165,9 +165,10 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
}
testDatasource(): Promise<{ status: string; message: string }> {
const refId = 'A';
return lastValueFrom(
getBackendSrv()
.fetch({
.fetch<BackendDataSourceResponse>({
url: '/api/ds/query',
method: 'POST',
data: {
@ -175,7 +176,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
to: 'now',
queries: [
{
refId: 'A',
refId: refId,
intervalMs: 1,
maxDataPoints: 1,
datasource: this.getRef(),
@ -187,7 +188,13 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
},
})
.pipe(
map(() => ({ status: 'success', message: 'Database Connection OK' })),
map((r) => {
const error = r.data.results[refId].error;
if (error) {
return { status: 'error', message: error };
}
return { status: 'success', message: 'Database Connection OK' };
}),
catchError((err) => {
return of(toTestingStatus(err));
})

Loading…
Cancel
Save