mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-06 06:17:11 -04:00
16 lines
324 B
JavaScript
16 lines
324 B
JavaScript
function withDefaultOnError(cb, defaultValue) {
|
|
try {
|
|
return cb();
|
|
} catch (_) {
|
|
return defaultValue;
|
|
}
|
|
}
|
|
async function withDefaultOnErrorAsync(cb, defaultValue) {
|
|
try {
|
|
return await cb();
|
|
} catch (_) {
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
export { withDefaultOnErrorAsync as a, withDefaultOnError as w };
|