Common
coderljw 2024-10-13 小于 1 分钟
# 1. await 错误处理
/**
* @param {Promise<any>} promise
* @return {Promise<any[]>} [error, result]
*/
export const awaitWarper = <E, V>(promise: Promise<V>) => {
return promise
.then((res: V) => [null, res])
.catch((err: E) => [err, null]) as Promise<[E, V]>
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9