bilibili/flv.js · error · RuntimeException
RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.s
Error message
RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText
What it means
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.
Source
Thrown at src/io/xhr-range-loader.js:217
if (xhr.responseURL !== this._currentRequestURL && redirectedURL !== this._currentRedirectedURL) {
this._currentRedirectedURL = redirectedURL;
if (this._onURLRedirect) {
this._onURLRedirect(redirectedURL);
}
}
}
if ((xhr.status >= 200 && xhr.status <= 299)) {
if (this._waitForTotalLength) {
return;
}
this._status = LoaderStatus.kBuffering;
} else {
this._status = LoaderStatus.kError;
if (this._onError) {
this._onError(LoaderErrors.HTTP_STATUS_CODE_INVALID, {code: xhr.status, msg: xhr.statusText});
} else {
throw new RuntimeException('RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);
}
}
}
}
_onProgress(e) {
if (this._status === LoaderStatus.kError) {
// Ignore error response
return;
}
if (this._contentLength === null) {
let openNextRange = false;
if (this._waitForTotalLength) {
this._waitForTotalLength = false;
this._totalLengthReceived = true;
openNextRange = true;View on GitHub (pinned to 42343088f2)
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.
Example fix
// before
player.load();
// after
player.on(flvjs.Events.ERROR, (type, data) => {
if (type === flvjs.ErrorTypes.NETWORK_ERROR) switchToFallbackUrl();
}); Defensive patterns
Strategy: try-catch
Validate before calling
async function preflight(url) {
const res = await fetch(url, {method: 'HEAD', headers: {Range: 'bytes=0-1'}});
if (!(res.status >= 200 && res.status <= 299)) throw new Error('Range request rejected: ' + res.status);
} Try / catch
try {
player.load();
} catch (e) {
if (/RangeLoader: Http code invalid/.test(e.message)) {
const code = Number((e.message.match(/invalid, (\d+)/) || [])[1] || 0);
if (code === 403) refreshTokenAndRetry();
else if (code === 404) switchToFallbackUrl();
} else throw e;
} Prevention
- 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.
When it happens
Trigger: An XHR range request for the FLV file responds with 403/404/416/5xx headers in _onReadyStateChange (src/io/xhr-range-loader.js:217).
Common situations: 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.
Related errors
- MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' +
- MSStreamLoader: Http code invalid, ' + xhr.status + ' ' + xh
- FetchStreamLoader: Http code invalid, ' + res.status + ' ' +
- IOException: ' + data.msg
- Fetch stream meet Early-EOF
AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01).
Data as JSON: /api/errors/77147177e961284d.
Report an issue: GitHub.