il || errorMsg;
                             } catch(e) { /* Ignore if response is not JSON */ }
                            throw new Error(errorMsg);
                        }

                        // Check if the response is JSON (likely an error before streaming started)
                        const contentType = response.headers.get('Content-Type');
                         if (contentType && contentType.includes('application/json')) {
                             const jsonData = await response.js