TelegramPWA/src/util/safeExec.ts
2023-04-25 17:27:10 +04:00

21 lines
432 B
TypeScript

import { DEBUG_MORE } from '../config';
import { handleError } from './handleError';
const SAFE_EXEC_ENABLED = !DEBUG_MORE;
export default function safeExec(cb: Function, rescue?: (err: Error) => void, always?: NoneToVoidFunction) {
if (!SAFE_EXEC_ENABLED) {
return cb();
}
try {
return cb();
} catch (err: any) {
rescue?.(err);
handleError(err);
return undefined;
} finally {
always?.();
}
}