All files / apps/huella-legal/app/composables useRequiredFetch.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                38x 3x   3x   2x    
import type { Ref } from "vue";
 
interface RequiredFetch {
    <T>(url: string): Promise<Ref<T | undefined>>;
    <T>(url: string, fallback: () => T): Promise<Ref<T>>;
}
 
/** A cached read of one of the core's routes that fails the page when the route does. */
export const useRequiredFetch: RequiredFetch = async (url: string, fallback?: () => unknown) => {
    const request = useCachedFetch<unknown>(url, { default: fallback });
 
    await useFailOnError(request);
 
    return request.data as Ref<never>;
};