{"record":{"id":"9eeea85484f611a4","repo":"ellite/Wallos","slug":"http-response-status","errorCode":null,"errorMessage":"HTTP ${response.status}","messagePattern":"HTTP \\$\\{response\\.status\\}","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/subscriptions.js","lineNumber":455,"sourceCode":"        } else {\r\n          showSearchState(resultsContainer, 'empty');\r\n        }\r\n      })\r\n      .catch(error => {\r\n        console.error(translate('error_fetching_image_results'), source.label, error);\r\n        showSearchState(resultsContainer, 'error');\r\n      });\r\n  });\r\n}\r\n\r\nfunction fetchLogoSearchSource(url, retry = true) {\r\n  return fetch(url, {\r\n    cache: \"no-store\",\r\n    headers: { \"Accept\": \"application/json\" },\r\n  })\r\n    .then(response => {\r\n      if (!response.ok) {\r\n        throw new Error(`HTTP ${response.status}`);\r\n      }\r\n      return response.text();\r\n    })\r\n    .then(body => {\r\n      try {\r\n        return JSON.parse(body);\r\n      } catch (error) {\r\n        throw new Error(\"Invalid JSON response\");\r\n      }\r\n    })\r\n    .catch(error => {\r\n      if (retry) {\r\n        // Wait a moment before retrying: sources like Brave rate-limit\r\n        // aggressively, and retrying instantly just repeats the failure.\r\n        return new Promise(resolve => setTimeout(resolve, 600))\r\n          .then(() => fetchLogoSearchSource(url, false));\r\n      }\r\n      throw error;\r","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/scripts/subscriptions.js#L437-L473","documentation":"This shared helper (used for fetching source data, e.g. from Brave and similar providers) throws a raw `HTTP ${response.status}` Error when response.ok is false. Unlike the settings errors, no localization and no response body are included — the consumer gets only the numeric status, e.g. 'HTTP 429' or 'HTTP 403'.","triggerScenarios":"The upstream source API responds with any non-2xx status: 429 when the provider rate-limits (the code comments on Brave doing this), 401/403 when the API key is missing or invalid, 404 for a wrong source URL, or 5xx provider outages.","commonSituations":"Aggressive polling of a rate-limited provider (429); expired or unconfigured API keys (401/403); provider downtime returning 502/503; mistyped source identifiers producing 404.","solutions":["Read the thrown status: 429 means back off and slow the polling interval; 401/403 means fix the API key/credentials.","Rely on the built-in retry path (the helper retries on failure) but back off longer when the status is 429 and honor Retry-After headers.","Verify the source URL and identifier are correct when the status is 404.","Wrap the call to catch this error and show a provider-specific message to the user instead of the raw status."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(`HTTP ${response.status}`);\n}\n// after\nif (!response.ok) {\n  const retryAfter = response.headers.get('Retry-After');\n  throw new Error(`HTTP ${response.status}${retryAfter ? ` (retry after ${retryAfter}s)` : ''}`);\n}","handlingStrategy":"retry","validationCode":"function isValidSourceUrl(url) {\n  try { const u = new URL(url); return u.protocol === 'https:' || u.protocol === 'http:'; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"fetchSourceData(url).catch(err => {\n  const m = /^HTTP (\\d+)$/.exec(err.message);\n  if (m && m[1] === '429') {\n    return scheduleRetryWithBackoff(url); // honor rate limit\n  }\n  if (m && (m[1] === '401' || m[1] === '403')) {\n    showProviderKeyError();\n  } else {\n    showGenericSourceError(err);\n  }\n});","preventionTips":["Throttle polling of rate-limited providers (Brave) and honor Retry-After headers.","Check API key configuration before making source requests.","Prefer exponential backoff with jitter over fixed-interval retries.","Validate source URLs/identifiers to avoid predictable 404s."],"tags":["network","http-error","api","rate-limit"],"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"}