This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
export { withDefaultOnError, withDefaultOnErrorAsync };
function withDefaultOnError<A, B>(cb: () => A, defaultValue: B): A | B {
try {
return cb();
}
catch (_) {
return defaultValue;
}
}
async function withDefaultOnErrorAsync<A, B>(cb: () => A, defaultValue: B): Promise<Awaited<A> | B> {
try {
return await cb();
}
catch (_) {
return defaultValue;
}
}