Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions website/src/components/views/wasap/useWasapPageData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dayjs from 'dayjs';
import { http } from 'msw';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { fetchWasapPageData, getLapisFilterForTimeFrame } from './useWasapPageData.ts';
import { fetchWasapPageData, getLapisFilterForTimeFrame, WasapValidationError } from './useWasapPageData.ts';
import {
EXCLUDE_SET_NAME,
SEQUENCE_TYPE,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('fetchWasapPageData', () => {
{},
{ mode: WASAP_ANALYSIS_MODE.manual, sequenceType: SEQUENCE_TYPE.nucleotide, mutations: [] },
),
).rejects.toThrow("Cannot fetch data, 'manual' mode is not enabled.");
).rejects.toThrow(WasapValidationError);
});
});

Expand Down Expand Up @@ -310,7 +310,7 @@ describe('fetchWasapPageData', () => {
timeFrame: VARIANT_TIME_FRAME.all,
},
),
).rejects.toThrow("Cannot fetch data, 'variant' mode is not enabled.");
).rejects.toThrow(WasapValidationError);
});
});

Expand Down Expand Up @@ -411,7 +411,7 @@ describe('fetchWasapPageData', () => {
{},
{ mode: WASAP_ANALYSIS_MODE.untracked, sequenceType: SEQUENCE_TYPE.nucleotide },
),
).rejects.toThrow("Cannot fetch data, 'untracked' mode is not enabled.");
).rejects.toThrow(WasapValidationError);
});
});

Expand Down Expand Up @@ -558,7 +558,7 @@ describe('fetchWasapPageData', () => {
{},
{ mode: WASAP_ANALYSIS_MODE.covSpectrumCollection, collectionId: 42 },
),
).rejects.toThrow("Cannot fetch data, 'covSpectrumCollection' mode is not enabled.");
).rejects.toThrow(WasapValidationError);
});

test('throws when no collection is selected', async () => {
Expand All @@ -568,7 +568,7 @@ describe('fetchWasapPageData', () => {
{},
{ mode: WASAP_ANALYSIS_MODE.covSpectrumCollection, collectionId: undefined },
),
).rejects.toThrow('No collection selected');
).rejects.toThrow(WasapValidationError);
});
});

Expand Down Expand Up @@ -938,13 +938,13 @@ describe('fetchWasapPageData', () => {

await expect(
fetchWasapPageData(disabledConfig, {}, { mode: WASAP_ANALYSIS_MODE.collection, collectionId: 1 }),
).rejects.toThrow("Cannot fetch data, 'collection' mode is not enabled.");
).rejects.toThrow(WasapValidationError);
});

test('throws when no collection is selected', async () => {
await expect(
fetchWasapPageData(config, {}, { mode: WASAP_ANALYSIS_MODE.collection, collectionId: undefined }),
).rejects.toThrow('No collection selected');
).rejects.toThrow(WasapValidationError);
});
});
});
Expand Down
34 changes: 22 additions & 12 deletions website/src/components/views/wasap/useWasapPageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import { getLineageFields } from '../../../types/Collection';
import type { FilterObject, Variant } from '../../../types/Collection';
import { validateGenomeOnly } from '../../../util/siloExpressionUtils';

export class WasapValidationError extends Error {
constructor(message: string) {
super(message);
this.name = 'WasapValidationError';
}
}

/**
* Hook that fetches and returns `WasapPageData` for the W-ASAP page,
* depending on the analysis mode and analysis mode settings.
Expand All @@ -38,6 +45,7 @@ export function useWasapPageData(
return useQuery({
queryKey: ['wasap', analysis, resistanceMutationsBySet],
queryFn: () => fetchWasapPageData(config, resistanceMutationsBySet, analysis),
retry: (failureCount, error) => !(error instanceof WasapValidationError) && failureCount < 3,
});
}

Expand All @@ -64,7 +72,7 @@ export async function fetchWasapPageData(

function fetchManualModeData(config: WasapPageConfig, analysis: WasapManualFilter): WasapMutationsData {
if (!config.manualAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'manual' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'manual' mode is not enabled.");
}
return {
type: 'mutations',
Expand All @@ -77,7 +85,7 @@ async function fetchVariantModeData(
analysis: WasapVariantFilter,
): Promise<WasapMutationsData> {
if (!config.variantAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'variant' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'variant' mode is not enabled.");
}
switch (analysis.signatureType) {
case 'computed':
Expand All @@ -92,7 +100,7 @@ async function fetchVariantComputedModeData(
analysis: WasapVariantFilter,
): Promise<WasapMutationsData> {
if (!config.variantAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'variant' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'variant' mode is not enabled.");
}
const mutationsWithScore = await getMutationsForVariant(
config.clinicalLapis.lapisBaseUrl,
Expand Down Expand Up @@ -124,10 +132,10 @@ async function fetchVariantPredefinedModeData(
analysis: WasapVariantFilter,
): Promise<WasapMutationsData> {
if (!config.variantAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'variant' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'variant' mode is not enabled.");
}
if (analysis.collectionId === undefined) {
throw new Error('No collection selected for predefined variant mode.');
throw new WasapValidationError('No collection selected for predefined variant mode.');
}
const collection = await getBackendServiceForClientside().getCollection({ id: String(analysis.collectionId) });

Expand All @@ -141,10 +149,12 @@ async function fetchVariantPredefinedModeData(

const variant = collection.variants.find((v) => v.name === variantName);
if (!variant) {
throw new Error(`Variant "${variantName}" not found in collection ${collection.id}.`);
throw new WasapValidationError(`Variant "${variantName}" not found in collection ${collection.id}.`);
}
if (variant.type !== 'filterObject') {
throw new Error(`Variant "${variantName}" in collection ${collection.id} is not a filterObject variant.`);
throw new WasapValidationError(
`Variant "${variantName}" in collection ${collection.id} is not a filterObject variant.`,
);
}

const mutations =
Expand Down Expand Up @@ -199,7 +209,7 @@ async function fetchUntrackedModeData(
analysis: WasapUntrackedFilter,
): Promise<WasapMutationsData> {
if (!config.untrackedAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'untracked' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'untracked' mode is not enabled.");
}
const variantsToExclude =
analysis.excludeSet === 'custom'
Expand Down Expand Up @@ -240,10 +250,10 @@ async function fetchCovSpectrumCollectionModeData(
analysis: WasapCovSpectrumCollectionFilter,
): Promise<WasapCollectionData> {
if (!config.covSpectrumCollectionAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'covSpectrumCollection' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'covSpectrumCollection' mode is not enabled.");
}
if (analysis.collectionId === undefined) {
throw Error('No collection selected');
throw new WasapValidationError('No collection selected');
}
const collection = await getCollection(config.collectionsApiBaseUrl, analysis.collectionId);

Expand All @@ -270,10 +280,10 @@ async function fetchCollectionModeData(
analysis: WasapCollectionFilter,
): Promise<WasapCollectionData> {
if (!config.collectionAnalysisModeEnabled) {
throw Error("Cannot fetch data, 'collection' mode is not enabled.");
throw new WasapValidationError("Cannot fetch data, 'collection' mode is not enabled.");
}
if (analysis.collectionId === undefined) {
throw Error('No collection selected');
throw new WasapValidationError('No collection selected');
}
const collection = await getBackendServiceForClientside().getCollection({ id: String(analysis.collectionId) });

Expand Down
Loading