Skip to content

Instantly share code, notes, and snippets.

@tomcask
Created February 23, 2018 07:59
Show Gist options
  • Save tomcask/e95933023ab4777d548cece7400be7b0 to your computer and use it in GitHub Desktop.
Save tomcask/e95933023ab4777d548cece7400be7b0 to your computer and use it in GitHub Desktop.
try to avoid use try catch statement and manage the error in await call
const to = promise =>{
return promise.then(data =>{
return [null, data]
})
.catch(err => [err])
}
fetchData(){
let err, data
[err, data] = await to(Api.getEntity())
if (err) { throw new Error(err)}
return new Entity(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment