Skip to content

Commit 51e3085

Browse files
authored
Add error catch to results of backend response (#12)
1 parent 606a565 commit 51e3085

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/DatasourceWithAsyncBackend.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@grafana/data';
99
import { BackendDataSourceResponse, DataSourceWithBackend, getBackendSrv, toDataQueryResponse } from '@grafana/runtime';
1010
import { merge, Observable, of } from 'rxjs';
11-
import { map } from 'rxjs/operators';
11+
import { catchError,map } from 'rxjs/operators';
1212
import { getRequestLooper } from './requestLooper';
1313

1414
export interface CustomMeta {
@@ -151,7 +151,9 @@ export class DatasourceWithAsyncBackend<
151151

152152
return getBackendSrv()
153153
.fetch<BackendDataSourceResponse>(options)
154-
.pipe(map((result) => ({ data: toDataQueryResponse(result).data })));
154+
.pipe(map((result) => ({ data: toDataQueryResponse(result).data })), catchError((err) => {
155+
return of(toDataQueryResponse(err));
156+
}));
155157
},
156158

157159
/**

0 commit comments

Comments
 (0)