async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); console.log('Data fetched successfully:', data); return data; } catch (error) { console.error('Error fetching data:', error); throw error; // Re-throw to allow caller to handle } } // Example usage: // fetchData('https://api.example.com/items') // .then(data => { // // Process data // }) // .catch(error => { // // Handle error // });