我破坏了端点以导致错误,但在调用函数时在 catch 语句中重新抛出错误以捕获它,但即使有错误,也会继续使用未定义的错误
const asyncours = async () => {
try {
const pos = await getPostion();
const { latitude: lat, longitude: lng } = pos.coords;
const requset = await fetch(
// here i add "s" at the end of endpoint to cause err
`https://geocode.xyz/${lat},${lng}?geoit=json&auth=727423644712354455137x109112s`
);
if (!requset.ok) throw new Error('this not valid country');
const data = await requset.json();
getCountry(data.country);
return `you are in ${data.city}, ${data.country}`;
} catch (err) {
console.error(`${err} 💥`);
renderError(`💥 ${err.message}`);
// Reject promise returned from async function
throw err;
}
};
(async function () {
try {
const city = await asyncours();
console.log(`2: ${city}`);
} catch (err) {
console.error(`2: ${err.message} 💥`);
}
})();
请帮助我尝试处理错误,但捕获永远不会到达