{"record":{"id":"77147177e961284d","repo":"bilibili/flv.js","slug":"rangeloader-http-code-invalid-xhr-status","errorCode":null,"errorMessage":"RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText","messagePattern":"RangeLoader: Http code invalid, ' \\+ xhr\\.status \\+ ' ' \\+ xhr\\.statusText","errorType":"http","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/io/xhr-range-loader.js","lineNumber":217,"sourceCode":"                if (xhr.responseURL !== this._currentRequestURL && redirectedURL !== this._currentRedirectedURL) {\n                    this._currentRedirectedURL = redirectedURL;\n                    if (this._onURLRedirect) {\n                        this._onURLRedirect(redirectedURL);\n                    }\n                }\n            }\n\n            if ((xhr.status >= 200 && xhr.status <= 299)) {\n                if (this._waitForTotalLength) {\n                    return;\n                }\n                this._status = LoaderStatus.kBuffering;\n            } else {\n                this._status = LoaderStatus.kError;\n                if (this._onError) {\n                    this._onError(LoaderErrors.HTTP_STATUS_CODE_INVALID, {code: xhr.status, msg: xhr.statusText});\n                } else {\n                    throw new RuntimeException('RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);\n                }\n            }\n        }\n    }\n\n    _onProgress(e) {\n        if (this._status === LoaderStatus.kError) {\n            // Ignore error response\n            return;\n        }\n\n        if (this._contentLength === null) {\n            let openNextRange = false;\n\n            if (this._waitForTotalLength) {\n                this._waitForTotalLength = false;\n                this._totalLengthReceived = true;\n                openNextRange = true;","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/io/xhr-range-loader.js#L199-L235","documentation":"RangeLoader (standard XHR range-request loader) treats any HTTP status outside 200-299 (excluding 0) as a fatal error at readyState 2. The loader transitions to kError and, absent an onError callback, throws RuntimeException containing the status code and statusText. This signals the server could not serve the requested byte ranges.","triggerScenarios":"An XHR range request for the FLV file responds with 403/404/416/5xx headers in _onReadyStateChange (src/io/xhr-range-loader.js:217).","commonSituations":"Hotlink protection returning 403, missing file (404), servers that do not honor Range requests properly, or CDN misconfiguration; visible on all browsers using the default XHR loader.","solutions":["Inspect code/statusText and fix the origin: correct URL, auth tokens, or enable Range support on the server.","Register onError to handle LoaderErrors.HTTP_STATUS_CODE_INVALID gracefully.","Add retry with fresh URL / alternate CDN on non-2xx responses."],"exampleFix":"// before\nplayer.load();\n// after\nplayer.on(flvjs.Events.ERROR, (type, data) => {\n    if (type === flvjs.ErrorTypes.NETWORK_ERROR) switchToFallbackUrl();\n});","handlingStrategy":"try-catch","validationCode":"async function preflight(url) {\n    const res = await fetch(url, {method: 'HEAD', headers: {Range: 'bytes=0-1'}});\n    if (!(res.status >= 200 && res.status <= 299)) throw new Error('Range request rejected: ' + res.status);\n}","typeGuard":null,"tryCatchPattern":"try {\n    player.load();\n} catch (e) {\n    if (/RangeLoader: Http code invalid/.test(e.message)) {\n        const code = Number((e.message.match(/invalid, (\\d+)/) || [])[1] || 0);\n        if (code === 403) refreshTokenAndRetry();\n        else if (code === 404) switchToFallbackUrl();\n    } else throw e;\n}","preventionTips":["Confirm the server supports Range requests (Accept-Ranges: bytes) before using the XHR loader.","Handle onError to receive HTTP_STATUS_CODE_INVALID instead of an uncaught throw.","Pre-flight HEAD checks and maintain alternate CDN sources.","Watch for hotlink-protection 403s caused by missing Referer/token config."],"tags":["http","network","loader","range-request"],"backgroundTag":"invalid-http-status-code","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}