{"record":{"id":"0c92df07fdda2420","repo":"BabylonJS/Babylon.js","slug":"failed-to-fetch-image-url-response-status","errorCode":null,"errorMessage":"Failed to fetch image \"${url}\": ${response.status} ${response.statusText}","messagePattern":"Failed to fetch image \"(.+?)\": (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/Textures/rawTexture2DArray.functions.ts","lineNumber":96,"sourceCode":"}\r\n\r\n/**\r\n * Fetches an image from a url, decodes it and uploads it into a single layer of a 2D array texture.\r\n * @param texture defines the 2D array texture to upload into\r\n * @param url defines the url of the image to load\r\n * @param layer defines the array layer to upload into\r\n * @param options defines optional upload settings (invertY, premultiplyAlpha)\r\n * @returns a promise resolved once the layer has been uploaded\r\n */\r\nexport async function LoadImageToTexture2DArrayLayerAsync(\r\n    texture: RawTexture2DArray,\r\n    url: string,\r\n    layer: number,\r\n    options?: IUploadImageToTexture2DArrayLayerOptions\r\n): Promise<void> {\r\n    const response = await fetch(url);\r\n    if (!response.ok) {\r\n        throw new Error(`Failed to fetch image \"${url}\": ${response.status} ${response.statusText}`);\r\n    }\r\n    const blob = await response.blob();\r\n    const bitmap = await createImageBitmap(blob);\r\n    try {\r\n        UploadImageToTexture2DArrayLayer(texture, bitmap, layer, options);\r\n    } finally {\r\n        bitmap.close();\r\n    }\r\n}\r\n\r\n/**\r\n * Options controlling the creation of a 2D array texture from a KTX2 file.\r\n */\r\nexport interface ICreateTexture2DArrayFromKTX2Options {\r\n    /** Defines if mip levels should be generated (true by default) */\r\n    generateMipMaps?: boolean;\r\n    /** Defines the sampling mode to use (Texture.TRILINEAR_SAMPLINGMODE by default) */\r\n    samplingMode?: number;\r","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/Textures/rawTexture2DArray.functions.ts#L78-L114","documentation":"LoadImageToTexture2DArrayLayerAsync fetches an image URL and throws a descriptive Error when the HTTP response is not ok (status outside 200-299), including the status code and status text in the message.","triggerScenarios":"Calling LoadImageToTexture2DArrayLayerAsync with a URL that 404s, 401/403s, or 5xx — wrong path, missing auth headers (fetch here sends no credentials), CORS-blocked or server-down responses.","commonSituations":"Typos in asset paths, images behind authentication, dev server without the asset folder, or CDN misconfiguration.","solutions":["Verify the URL resolves in the browser/curl and returns 200","Add authentication headers via a pre-fetched blob or proxy if the asset is protected","Check dev-server/CDN config serves the image (public path, base URL)","Handle 404 by checking the asset build includes the image"],"exampleFix":"// before\nawait LoadImageToTexture2DArrayLayerAsync(tex, `/textures/${name}.png`, i);\n// after\nconst url = new URL(`/textures/${name}.png`, import.meta.env.ASSET_BASE).href;\nconst res = await fetch(url);\nif (!res.ok) throw new Error(`Missing asset ${url}: ${res.status}`);\nawait LoadImageToTexture2DArrayLayerAsync(tex, url, i);","handlingStrategy":"retry","validationCode":"async function assertFetchable(url: string): Promise<Response> {\n  const res = await fetch(url, { method: \"HEAD\" });\n  if (!res.ok) throw new Error(`Image ${url} not available: ${res.status}`);\n  return res;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await LoadImageToTexture2DArrayLayerAsync(tex, url, layer);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Failed to fetch image\")) {\n    if (isTransient(e)) await retry(() => LoadImageToTexture2DArrayLayerAsync(tex, url, layer), 3);\n    else usePlaceholderLayer(layer);\n  } else throw e;\n}","preventionTips":["HEAD-check asset URLs at startup","Include assets in build output verification","Add retry with backoff for transient network failures","Serve protected assets through an authenticated proxy"],"tags":["network","fetch","http-status"],"backgroundTag":"http-request-failed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}