با دقت به این کد نگاه کنید:
app.get('/posts', async (req, res) => {
try {
const response = fetch('https://example.com/api/posts');
response
.then(r => r.json())
.then(data => {
res.json({
success: true,
posts: data
});
})
.catch(err => {
console.error('Fetch error:', err);
res.status(500).json({ message: 'Internal error' });
});
} catch (err) {
console.error('Route error:', err);
res.status(500).json({ message: 'Route failed' });
}
});چه چیزی باید در این کد اصلاح شود تا استفاده از async/await و مدیریت خطا به شکل درست و قابل پیشبینی انجام شود؟
🔖 #Web #وب #Frontend #Backend
👤 Developix
💎 Channel: @DevelopixWeb
