mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Use queryFn instead of query to be able to catch errors in onCall req… (#60685)
Use queryFn instead of query to be able to catch errors in onCall request
This commit is contained in:
parent
9ce1cd9ddf
commit
22ad487c4b
@ -1,3 +1,7 @@
|
|||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
|
||||||
|
import { getBackendSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
import { alertingApi } from './alertingApi';
|
import { alertingApi } from './alertingApi';
|
||||||
export interface OnCallIntegration {
|
export interface OnCallIntegration {
|
||||||
integration_url: string;
|
integration_url: string;
|
||||||
@ -8,13 +12,26 @@ export type OnCallIntegrationsUrls = string[];
|
|||||||
export const onCallApi = alertingApi.injectEndpoints({
|
export const onCallApi = alertingApi.injectEndpoints({
|
||||||
endpoints: (build) => ({
|
endpoints: (build) => ({
|
||||||
getOnCallIntegrations: build.query<OnCallIntegrationsUrls, void>({
|
getOnCallIntegrations: build.query<OnCallIntegrationsUrls, void>({
|
||||||
query: () => ({
|
queryFn: async () => {
|
||||||
headers: {},
|
const integrations = await fetchOnCallIntegrations();
|
||||||
url: '/api/plugin-proxy/grafana-oncall-app/api/internal/v1/alert_receive_channels/',
|
return { data: integrations };
|
||||||
}),
|
},
|
||||||
providesTags: ['AlertmanagerChoice'],
|
providesTags: ['AlertmanagerChoice'],
|
||||||
transformResponse: (response: OnCallIntegrationsResponse) => response.map((result) => result.integration_url),
|
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
export async function fetchOnCallIntegrations(): Promise<OnCallIntegrationsUrls> {
|
||||||
|
try {
|
||||||
|
const response = await lastValueFrom(
|
||||||
|
getBackendSrv().fetch<OnCallIntegrationsResponse>({
|
||||||
|
url: '/api/plugin-proxy/grafana-oncall-app/api/internal/v1/alert_receive_channels/',
|
||||||
|
showErrorAlert: false,
|
||||||
|
showSuccessAlert: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return response.data.map((result) => result.integration_url);
|
||||||
|
} catch (error) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
export const { useGetOnCallIntegrationsQuery } = onCallApi;
|
export const { useGetOnCallIntegrationsQuery } = onCallApi;
|
||||||
|
Loading…
Reference in New Issue
Block a user