You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/azure/queries/useSubscription.ts

45 lines
1.1 KiB

import { useQuery } from '@tanstack/react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { withError } from '@/react-tools/react-query';
import { Subscription } from '../types';
import { azureErrorParser } from '../services/utils';
import { queryKeys } from './query-keys';
import { buildSubscriptionsUrl } from './utils';
export function useSubscription(
environmentId: EnvironmentId,
subscriptionId: string
) {
return useQuery(
queryKeys.subscription(environmentId, subscriptionId),
() => getSubscription(environmentId, subscriptionId),
{
...withError('Unable to retrieve Azure subscription'),
}
);
}
async function getSubscription(
environmentId: EnvironmentId,
subscriptionId: string
) {
try {
const { data } = await axios.get<Subscription>(
buildSubscriptionsUrl(environmentId, subscriptionId),
{ params: { 'api-version': '2016-06-01' } }
);
return data;
} catch (e) {
throw parseAxiosError(
e as Error,
'Unable to retrieve subscription',
azureErrorParser
);
}
}