Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

623 B
Raw Blame
import type { AppRouter } from '@openpanel/core';
import type { TRPCClientErrorBase } from '@trpc/client';
import { createTRPCContext } from '@trpc/tanstack-react-query';
import { type ExternalToast, toast } from 'sonner';

export const { TRPCProvider, useTRPC } = createTRPCContext<AppRouter>();

export function handleError(error: TRPCClientErrorBase<any>) {
  toast('Error', {
    description: error.message,
  });
}

export function handleErrorToastOptions(options: ExternalToast) {
  return (error: TRPCClientErrorBase<any>) => {
    toast('Error', {
      description: error.message,
      ...options,
    });
  };
}