Skip to content

Commit

Permalink
Fix showing connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Nov 12, 2023
1 parent 27987e4 commit c7acd17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('Trino datasource', () => {

const ds = new DataSource({ name: '', id: 0, jsonData: {} } as any);
const result = await ds.testDatasource();
expect(result.status).toEqual(400);
expect(result.message).toEqual('Query error: 400 Bad Request');
expect(result.status).toEqual("error");
expect(result.message).toEqual('Query error: Bad Request');
});
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
import { DataSourceWithBackend, getBackendSrv, getTemplateSrv, toDataQueryError } from '@grafana/runtime';
import { DataSourceWithBackend, getBackendSrv, getTemplateSrv } from '@grafana/runtime';
import { TrinoDataSourceOptions, TrinoQuery } from './types';
import { TrinoDataVariableSupport } from './variable';
import { lastValueFrom, of } from 'rxjs';
Expand Down Expand Up @@ -40,7 +40,10 @@ export class DataSource extends DataSourceWithBackend<TrinoQuery, TrinoDataSourc
.pipe(
mapTo({ status: 'success', message: 'Database Connection OK' }),
catchError((err) => {
return of(toDataQueryError(err));
return of({
status: 'error',
message: err.error ? err.error : (err.statusText ? ("Query error: " + err.statusText) : "Error connecting to Trino"),
});
})
)
);
Expand Down

0 comments on commit c7acd17

Please sign in to comment.