@nozbe/watermelondb
Version:
Build powerful React Native and React web apps that scale from hundreds to tens of thousands of records and remain fast
27 lines (20 loc) • 812 B
JavaScript
// @flow
export type DiagnosticErrorFunction = (string) => Error
let customDiagnosticErrorFunction: ?DiagnosticErrorFunction = null
// Use this to replace default diagnosticError function to inject your custom logic
// (e.g. only display errors in development, or log errors to external service)
export function useCustomDiagnosticErrorFunction(
diagnosticErrorFunction: DiagnosticErrorFunction,
): void {
customDiagnosticErrorFunction = diagnosticErrorFunction
}
export default function diagnosticError(errorMessage: string): Error {
if (customDiagnosticErrorFunction) {
return customDiagnosticErrorFunction(errorMessage)
}
const error: any = new Error(errorMessage)
// hides `diagnosticError` from RN stack trace
error.framesToPop = 1
error.name = 'Diagnostic error'
return error
}