UNPKG
try-to-catch
Version:
latest (3.0.1)
3.0.1
3.0.0
2.0.1
2.0.0
1.1.1
1.1.0
1.0.2
1.0.1
1.0.0
function try-catch wrapper for promises
github.com/coderaiser/try-to-catch
coderaiser/try-to-catch
try-to-catch
/
lib
/
try-to-catch.js
18 lines
(13 loc)
•
283 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'use strict'
;
module
.
exports
=
async
(fn, ...args) => {
check
(fn);
try
{
return
[
null
,
await
fn
(...args)]; }
catch
(e) {
return
[e]; } };
function
check
(
fn
) {
if
(
typeof
fn !==
'function'
)
throw
Error
(
'fn should be a function!'
); }