{"record":{"id":"a06179f56dbf4828","repo":"dotnet/maui","slug":"http-error-response-status","errorCode":null,"errorMessage":"HTTP error: ${response.status}","messagePattern":"HTTP error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/index.html","lineNumber":35,"sourceCode":"            \"HybridWebViewMessageReceived\",\n            function (e) {\n                LogMessage(\"Raw message: \" + e.detail.message);\n            });\n\n        function AddNumbers(a, x, b, y) {\n            var result = {\n                \"result\": a + b,\n                \"operationName\": \"Addition\"\n            };\n            return result;\n        }\n\n        var count = 0;\n\n        async function EvaluateMeWithParamsAndAsyncReturn(s1, s2) {\n            const response = await fetch(\"/asyncdata.txt\");\n            if (!response.ok) {\n                throw new Error(`HTTP error: ${response.status}`);\n            }\n            var jsonData = await response.json();\n\n            jsonData[s1] = s2;\n\n            const msg = 'JSON data is available: ' + JSON.stringify(jsonData);\n            window.HybridWebView.SendRawMessage(msg)\n\n            return jsonData;\n        }\n\n\n        async function InvokeDoSyncWork() {\n            LogMessage(\"Invoking DoSyncWork\");\n            await window.HybridWebView.InvokeDotNet('DoSyncWork');\n            LogMessage(\"Invoked DoSyncWork\");\n        }\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/index.html#L17-L53","documentation":"A JavaScript Error thrown inside the HybridWebView sample when fetch('/asyncdata.txt') returns a non-OK HTTP status. It is the sample's own guard around the embedded HTTP host that serves the Raw asset folder. The asset exists in the repo, so this fires only when the hybrid host fails to serve it or returns a non-2xx status.","triggerScenarios":"EvaluateMeWithParamsAndAsyncReturn runs and the WebView's internal HTTP host returns non-200 for /asyncdata.txt: the asset was not bundled (wrong/missing MauiAsset build action), the host serves assets from a different root path, or the HTML ran outside the hybrid host (e.g. a plain browser) where the route 404s.","commonSituations":"Adding/removing asyncdata.txt without setting build action to MauiAsset; renaming the HybridSamplePage Raw folder so the path mapping breaks; debugging the HTML in a normal browser where /asyncdata.txt is not routed; platform-specific host differences in how Raw resources are served.","solutions":["Verify asyncdata.txt is under Resources/Raw/HybridSamplePage with build action MauiAsset (MauiAsset / RawAsset per platform).","Check response.status in the WebView's debugging console to confirm whether it is 404 vs another error.","Ensure the fetch path matches the root the hybrid host actually serves; adjust to a relative path if the host mounts the folder elsewhere."],"exampleFix":"// before\nconst response = await fetch(\"/asyncdata.txt\");\nif (!response.ok) {\n  throw new Error(`HTTP error: ${response.status}`);\n}\n\n// after\nconst response = await fetch(\"asyncdata.txt\");\nif (!response.ok) {\n  throw new Error(`HTTP error: ${response.status}`);\n}","handlingStrategy":"validation","validationCode":"async function safeFetchJson(url) {\n  const response = await fetch(url);\n  if (!response.ok) {\n    console.warn(`Asset ${url} unavailable (HTTP ${response.status}); using fallback.`);\n    return {};\n  }\n  return response.json();\n}","typeGuard":null,"tryCatchPattern":"try {\n  const data = await safeFetchJson('asyncdata.txt');\n} catch (e) {\n  // network/host error, not just non-OK status\n  console.error('fetch failed', e);\n}","preventionTips":["Confirm every fetched asset is in Resources/Raw/<Folder> with the MauiAsset build action.","Use the same root path the hybrid host actually serves (prefer relative paths).","Develop JS against the hybrid host, not a plain browser, so asset routes resolve identically."],"tags":["hybridwebview","javascript","http","fetch","assets","sample"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}