Created
January 16, 2019 17:17
-
-
Save icodesido/626d26d9f33fc0e7c4cec4cbd92ea518 to your computer and use it in GitHub Desktop.
catch errors on multiple awaits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function connect() { | |
const | |
connection = await asyncDBconnect('http://localhost:1234'), | |
session = await asyncGetSession(connection), | |
user = await asyncGetUser(session), | |
log = await asyncLogAccess(user); | |
return true; | |
} | |
// higher-order function to catch errors | |
function catchErrors(fn) { | |
return function (...args) { | |
return fn(...args).catch(err => { | |
console.log('ERROR', err); | |
}); | |
} | |
} | |
(async () => { | |
await catchErrors(connect)(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment