一、我只是console一下,我不處理。
async function getData(){
const a = await someFunction().catch((error)=>console.log(error));
const b = await someOtherFunction().catch((error)=>console.log(error));
if(a && b ) console.log("some result")
}
二、約定法則
const go = async () => {
const readFileResult = await sureThing(readFile('some.json'));
if (readFileResult.ok) {
const {
ok,
error,
data
} = await sureThing(parseJSON(data));
if (ok) {
// use our data
} else {
return {
ok,
error
};
}
} else {
return readFileResult;
}
};
try{
let a = await func();
//如果resolve,此處的a爲resolve的值
}catch(e){
//如果reject了,此處的e爲reject的錯誤
}