expo-popcore-app/hooks/use-error.ts

11 lines
263 B
TypeScript

import { type ApiError } from '@/lib/types'
export async function handleError<T>(cb: () => Promise<T>) {
try {
const data = await cb()
return { data, error: null }
} catch (e) {
return { data: null, error: e as ApiError }
}
}