Created
April 4, 2020 14:40
-
-
Save nbhaohao/1e36523792338fc5b5cdafb1617a7cd0 to your computer and use it in GitHub Desktop.
async/await 优雅的错误处理方法
This file contains 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
function awaitWrap<T, U = any>(promise: Promise<T>): Promise<[U | null, T | null]> { | |
return promise | |
.then<[null, T]>((data: T) => [null, data]) | |
.catch<[U, null]>(err => [err, null]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
转载自:
作者:Vincent.W
链接:https://juejin.im/post/5c49eb28f265da613a545a4b
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。