All files / web/src/contexts ArcadeErrorContext.tsx

100% Statements 38/38
100% Branches 5/5
100% Functions 2/2
100% Lines 38/38

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 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 2x 2x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 7x 7x 4x 4x 3x 3x  
'use client'
 
import React, { createContext, useContext, useCallback, type ReactNode } from 'react'
import { useToast } from '@/components/common/ToastContext'
 
interface ArcadeErrorContextValue {
  addError: (message: string, details?: string) => void
}
 
export const ArcadeErrorContext = createContext<ArcadeErrorContextValue | null>(null)
 
/**
 * Provider for arcade error management
 * Uses the existing Radix-based toast system for error notifications
 */
export function ArcadeErrorProvider({ children }: { children: ReactNode }) {
  const { showError } = useToast()
 
  const addError = useCallback(
    (message: string, details?: string) => {
      showError(message, details)
    },
    [showError]
  )
 
  return <ArcadeErrorContext.Provider value={{ addError }}>{children}</ArcadeErrorContext.Provider>
}
 
/**
 * Hook to access arcade error context
 */
export function useArcadeError() {
  const context = useContext(ArcadeErrorContext)
  if (!context) {
    throw new Error('useArcadeError must be used within ArcadeErrorProvider')
  }
  return context
}