All files / src/hooks/exports asyncExport.helpers.ts

100% Statements 5/5
100% Branches 7/7
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 17    540x             540x       14x 11x    
import type { BackgroundTaskError } from "@customTypes/backgroundTasks";
 
export const EXPORT_FAILED_MESSAGE = "Export failed. Please try again.";
 
/**
 * A failed task's `error` is an object, so it must never reach a toast as-is:
 * React throws "Objects are not valid as a React child" while rendering it,
 * which unmounts the whole app instead of showing the failure.
 */
export const getTaskErrorMessage = (
  error: string | BackgroundTaskError | null | undefined,
  fallback: string = EXPORT_FAILED_MESSAGE,
): string => {
  if (typeof error === "string") return error.trim() || fallback;
  return error?.message?.trim() || fallback;
};