{"record":{"id":"2cda0e1d37d43089","repo":"koala73/worldmonitor","slug":"failed-to-register-push-subscription-res-status","errorCode":null,"errorMessage":"Failed to register push subscription (${res.status})${code ? `: ${code}` : ''}.","messagePattern":"Failed to register push subscription \\((.+?)\\)(.+?)` : ''\\}\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/push-notifications.ts","lineNumber":215,"sourceCode":"    const parsed: unknown = JSON.parse(await res.text());\n    const error = (parsed as { error?: unknown } | null)?.error;\n    if (typeof error === 'string' && error) code = error.slice(0, 120);\n  } catch {\n    // Non-JSON body (or an unreadable stream) — the status is all we have.\n  }\n  return `Failed to register push subscription (${res.status})${code ? `: ${code}` : ''}.`;\n}\n\nasync function postSubscription(\n  payload: SubscriptionPayload,\n  expectedUserId?: string,\n): Promise<void> {\n  const res = await authFetch('/api/notification-channels', {\n    method: 'POST',\n    body: JSON.stringify({ action: 'set-web-push', ...payload }),\n  }, expectedUserId);\n  if (!res.ok) {\n    throw new Error(await describePushRegistrationFailure(res));\n  }\n}\n\n/** Reverse of subscribeToPush: unregisters with the server and the browser. */\nexport async function unsubscribeFromPush(): Promise<void> {\n  const reg = await getRegistration();\n  if (reg) {\n    const sub = await reg.pushManager.getSubscription().catch(() => null);\n    if (sub) {\n      // Best-effort browser-side unsubscribe. If the network delete\n      // fails we still want the browser subscription removed so the\n      // user isn't left with a phantom channel.\n      await sub.unsubscribe().catch(() => {});\n    }\n  }\n  try {\n    await authFetch('/api/notification-channels', {\n      method: 'POST',","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/src/services/push-notifications.ts#L197-L233","documentation":"UI error in postSubscription (push-notifications): the server rejected the registration POST to /api/notification-channels with a non-OK status. The status code and any JSON 'error' field (up to 120 chars) are included in the message to identify the server-side reason.","triggerScenarios":"Thrown at src/services/push-notifications.ts:215 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Address the server 'code' if present (e.g. invalid payload, duplicate subscription)","Retry on transient 5xx statuses","Check authentication if the status is 401/403 — the session may have expired"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}