{"record":{"id":"0b13251b4ee018a2","repo":"ellite/Wallos","slug":"translate-network-response-error-subscriptions","errorCode":null,"errorMessage":"translate(\"network_response_error\")","messagePattern":"translate\\(\"network_response_error\"\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/subscriptions.js","lineNumber":258,"sourceCode":"    });\r\n}\r\n\r\n\r\nfunction cloneSubscription(event, id) {\r\n  event.stopPropagation();\r\n  event.preventDefault();\r\n\r\n  fetch(\"endpoints/subscription/clone.php\", {\r\n    method: \"POST\",\r\n    headers: {\r\n      \"Content-Type\": \"application/json\",\r\n      \"X-CSRF-Token\": window.csrfToken,\r\n    },\r\n    body: JSON.stringify({ id: id }),\r\n  })\r\n    .then((response) => {\r\n      if (!response.ok) {\r\n        throw new Error(translate(\"network_response_error\"));\r\n      }\r\n      return response.json();\r\n    })\r\n    .then((data) => {\r\n      if (data.success) {\r\n        const newId = data.id;\r\n        fetchSubscriptions(newId, event, \"clone\");\r\n        showSuccessMessage(decodeURI(data.message));\r\n      } else {\r\n        showErrorMessage(data.message || translate(\"error\"));\r\n      }\r\n    })\r\n    .catch((error) => {\r\n      showErrorMessage(error.message || translate(\"error\"));\r\n    });\r\n}\r\n\r\n\r","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/scripts/subscriptions.js#L240-L276","documentation":"cloneSubscription POSTs {id} with a CSRF header to a subscriptions endpoint and throws the generic localized network_response_error whenever the response status is not OK. As in renamePayment, the specific HTTP failure is collapsed into one user-facing message, discarding the status code and any server-provided details.","triggerScenarios":"The clone endpoint returns non-2xx: unknown or already-deleted subscription id causing a 404, CSRF token mismatch returning 419/403, session expiry, or a server 500 while duplicating the subscription record.","commonSituations":"Clicking 'clone' on a subscription deleted in another tab (404); stale page/session producing CSRF rejection; database constraint failures during the clone causing 500.","solutions":["Retry the clone while watching the Network tab to capture the real status code and response payload.","Reload the page to refresh the session and window.csrfToken before cloning again.","Confirm the subscription id still exists server-side (it may have been deleted concurrently).","Enhance the throw to include response.status and the parsed error message, mirroring the fetchJson helper pattern used elsewhere in the codebase."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(translate(\"network_response_error\"));\n}\nreturn response.json();\n// after\nif (!response.ok) {\n  const body = await response.text();\n  let msg = \"\";\n  try { msg = JSON.parse(body).message ?? \"\"; } catch (e) {}\n  throw new Error(`${translate(\"network_response_error\")} (HTTP ${response.status})${msg ? \": \" + msg : \"\"}`);\n}\nreturn response.json();","handlingStrategy":"try-catch","validationCode":"function canCloneSubscription(id) {\n  return Number.isInteger(id) && id > 0 && typeof window.csrfToken === 'string' && window.csrfToken.length > 0;\n}","typeGuard":null,"tryCatchPattern":"cloneSubscription(id).catch(err => {\n  if (err.message.includes('network_response_error')) {\n    showErrorMessage(translate('network_response_error') + ' — reload the page and retry');\n  } else {\n    showErrorMessage(err.message);\n  }\n});","preventionTips":["Verify the subscription still exists before cloning (it may have been deleted in another tab).","Reload the page to refresh session/CSRF state after long inactivity.","Return JSON error bodies with messages from the clone endpoint.","Watch the Network tab on failure to identify the real status code."],"tags":["network","fetch","http-error","javascript"],"backgroundTag":"http-error-response","analyzedSha":"52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd","analyzedAt":"2026-09-13T14:09:30.873Z","contentChangedAt":"2026-09-13T14:09:30.873Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}