{"record":{"id":"2349bb87f069c707","repo":"dotnet/orleans","slug":"network-response-was-not-ok","errorCode":null,"errorMessage":"Network response was not ok","messagePattern":"Network response was not ok","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"playground/ActivationRepartitioning/ActivationRepartitioning.Frontend/wwwroot/index.html","lineNumber":338,"sourceCode":"          height = svg.node().clientHeight;\n          state.simulation.force(\n            \"center\",\n            d3.forceCenter(width / 2, height / 2)\n          );\n          state.simulation.alpha(1).restart();\n        });\n      }\n\n      async function postRequest(url) {\n        try {\n          const response = await fetch(url, {\n            method: \"POST\",\n            headers: {\n              \"Content-Type\": \"application/json\",\n            },\n          });\n          if (!response.ok) {\n            throw new Error(\"Network response was not ok\");\n          }\n          await loadData();\n        } catch (error) {\n          console.error(\"Error with the fetch operation:\", error);\n        }\n      }\n\n      document\n        .getElementById(\"addGrainsButton\")\n        .addEventListener(\"click\", () => {\n          postRequest(\"/add\");\n        });\n\n      document.getElementById(\"resetButton\").addEventListener(\"click\", () => {\n        postRequest(\"/reset\");\n      });\n    </script>\n  </body>","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/playground/ActivationRepartitioning/ActivationRepartitioning.Frontend/wwwroot/index.html#L320-L356","documentation":"A browser-side Error thrown by postRequest() in the ActivationRepartitioning frontend when a POST (e.g., to /add) returns a non-2xx status. Like all fetch calls, the network layer only rejects on network failure, so the code checks response.ok manually and throws to send control into the catch, which logs the error and swallows it.","triggerScenarios":"Clicking the 'Add Grains' button (or any control wired to postRequest) issues fetch(url,{method:'POST'}) and the server responds with an error status. The accompanying loadData() refresh is skipped because the throw precedes it.","commonSituations":"The backend grain-add endpoint rejected the request (capacity, validation, or a thrown exception in the grain). The Orleans client lost connectivity to the cluster. The endpoint route changed.","solutions":["Inspect the response status/body in devtools Network tab for the failing POST to read the server-side error.","Check backend logs for the exception thrown while handling the POST.","Verify the cluster client is still connected (gateway reachable) before issuing the POST."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(\"Network response was not ok\");\n}\n\n// after (include status for actionable diagnostics)\nif (!response.ok) {\n  throw new Error(`Request to ${url} failed: ${response.status} ${response.statusText}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function postRequest(url) {\n  try {\n    const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' } });\n    if (!response.ok) throw new Error(`${url} failed: ${response.status}`);\n    await loadData();\n  } catch (error) {\n    console.error('Fetch failed:', error);\n    alert('Operation failed: ' + error.message);\n  }\n}","preventionTips":["Include status and URL in thrown errors for traceability.","Give the user feedback (toast/alert) on failure rather than silently logging.","Validate any request body before posting to reduce 4xx errors."],"tags":["javascript","fetch","frontend","http","network"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}