try { // Make the API call logs.push(`Making API call to URL: ${url}`); const response = await fetch(url, config);
// Check if the response status is OK if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); }
// Extract the JSON body from the response logs.push("Extracting JSON from the response"); const responseBody = await response.json;
// Validate the responseBody structure as expected if (!responseBody || !responseBody.order || typeof responseBody.order !== 'object') { throw new Error("Invalid or missing response body from the API"); }