{"record":{"id":"738b37dfa59da050","repo":"gildas-lormeau/SingleFile","slug":"response-statustext-error-response-statu","errorCode":null,"errorMessage":"(response.statusText || (\"Error \" + response.status)) + \" (Woleet)\"","messagePattern":"\\(response\\.statusText \\|\\| \\(\"Error \" \\+ response\\.status\\)\\) \\+ \" \\(Woleet\\)\"","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/woleet/woleet.js","lineNumber":53,"sourceCode":"\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\"Authorization\": \"Bearer \" + bearer\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\t\"name\": hash,\n\t\t\t\"hash\": hash,\n\t\t\t\"public\": true\n\t\t})\n\t});\n\tif (response.status == 401) {\n\t\tconst error = new Error(\"Your access token on Woleet is invalid. Go to __DOC_LINK__ to create your account.\");\n\t\terror.link = \"https://app.woleet.io/\";\n\t\tthrow error;\n\t} else if (response.status == 402) {\n\t\tconst error = new Error(\"You have no more credits on Woleet. Go to __DOC_LINK__ to recharge them.\");\n\t\terror.link = \"https://app.woleet.io/\";\n\t\tthrow error;\n\t} else if (response.status >= 400) {\n\t\tthrow new Error((response.statusText || (\"Error \" + response.status)) + \" (Woleet)\");\n\t}\n\treturn response.json();\n}","sourceCodeStart":35,"sourceCodeEnd":56,"githubUrl":"https://github.com/gildas-lormeau/SingleFile/blob/517fb7c5cf2096d89933b747e862d8ecf616a9f9/src/lib/woleet/woleet.js#L35-L56","documentation":"The Woleet anchoring client wraps API calls and throws an Error combining the HTTP statusText (or a fallback 'Error <status>') with the ' (Woleet)' suffix whenever the API responds with status >= 400. Status 402 is special-cased first to give a credits-exhausted message with a recharge link. This generic branch covers all other client/server errors returned by the Woleet API.","triggerScenarios":"anchor() (or the shared request helper it flows through) receives a Woleet API response with status >= 400 that is not 402 and not handled by an earlier branch, e.g. 400 bad payload, 401/403 invalid API token, 404 unknown anchor id, 429 rate-limited, or 5xx server error.","commonSituations":"Expired or revoked Woleet API token (401/403); malformed anchor request body (400); exceeding API rate limits (429); Woleet service outage or maintenance returning 5xx; using a deprecated API endpoint after a Woleet version change.","solutions":["Inspect the statusText in the message to identify the cause; log the full error including the numeric status fallback.","Refresh or regenerate the Woleet API token if status is 401/403.","Validate the anchor payload (digest, anchor id) matches the Woleet API schema if status is 400.","If status is 429 or 5xx, retry with exponential backoff; check Woleet service status for outages."],"exampleFix":"// before\nawait woleet.anchor(digest); // 'Unauthorized (Woleet)' from stale token\n// after\nif (!woleetTokenIsValid()) token = await refreshWoleetToken();\ntry {\n  await woleet.anchor(digest);\n} catch (e) {\n  if (e.message.includes('429')) await sleep(backoff) /* then retry */;\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Validate preconditions before calling the Woleet API\nif (!apiKey) throw new Error('Woleet API token missing');\nif (!/^[0-9a-f]{64}$/i.test(digest)) throw new Error('Invalid digest format for Woleet anchor');","typeGuard":"function isWoleetApiError(e) {\n  return e instanceof Error && e.message.endsWith('(Woleet)');\n}\nfunction woleetStatus(e) {\n  const m = /Error (\\d{3}) \\(Woleet\\)$/.exec(e.message);\n  return m ? Number(m[1]) : null;\n}","tryCatchPattern":"try {\n  await woleet.anchor(digest);\n} catch (e) {\n  if (isWoleetApiError(e)) {\n    const s = woleetStatus(e);\n    if (s === 401 || s === 403) { await rotateToken(); return retry(); }\n    if (s === 429 || s >= 500) { await backoff(); return retry(); }\n    if (s === 402) { /* special-cased upstream: surface recharge link */ }\n  }\n  throw e;\n}","preventionTips":["Keep the Woleet API token fresh; rotate before expiry.","Validate digests and payload shape against the Woleet API docs before calls.","Implement exponential backoff for 429/5xx instead of failing fast.","Watch credits balance separately so 402 (credits exhausted) is handled via its dedicated message/link."],"tags":["woleet","api","http-status","anchor"],"backgroundTag":"http-api-error","analyzedSha":"517fb7c5cf2096d89933b747e862d8ecf616a9f9","analyzedAt":"2026-09-01T10:05:25.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}