24 lines
488 B
TypeScript

export const managePb404 = async <T>(
dbFunc: () => Promise<T>
): Promise<T | null> => {
try {
return await dbFunc()
} catch (err: any) {
if (err?.message === "The requested resource wasn't found.") {
return null
} else throw err
}
}
export const managePbError = async <T>(
dbFunc: () => Promise<T>,
defaultVal?: T
): Promise<T | null> => {
try {
return await dbFunc()
} catch (err: any) {
console.error(err)
return defaultVal || null
}
}