bilibili/flv.js · error · RuntimeException
FetchStreamLoader: Http code invalid, ' + res.status + ' ' +
Error message
FetchStreamLoader: Http code invalid, ' + res.status + ' ' + res.statusText
What it means
FetchStreamLoader.open() checks the fetch() Response; if response.ok is false (non-2xx HTTP status) the loader enters kError state. Normally it reports the failure via the onError callback with LoaderErrors.HTTP_STATUS_CODE_INVALID, but when no onError handler is registered it throws RuntimeException 'FetchStreamLoader: Http code invalid, <status> <statusText>'. It is the library surfacing an HTTP-level rejection from the streaming fetch.
Source
Thrown at src/io/fetch-stream-loader.js:157
}
let lengthHeader = res.headers.get('Content-Length');
if (lengthHeader != null) {
this._contentLength = parseInt(lengthHeader);
if (this._contentLength !== 0) {
if (this._onContentLengthKnown) {
this._onContentLengthKnown(this._contentLength);
}
}
}
return this._pump.call(this, res.body.getReader());
} else {
this._status = LoaderStatus.kError;
if (this._onError) {
this._onError(LoaderErrors.HTTP_STATUS_CODE_INVALID, {code: res.status, msg: res.statusText});
} else {
throw new RuntimeException('FetchStreamLoader: Http code invalid, ' + res.status + ' ' + res.statusText);
}
}
}).catch((e) => {
if (this._abortController && this._abortController.signal.aborted) {
return;
}
this._status = LoaderStatus.kError;
if (this._onError) {
this._onError(LoaderErrors.EXCEPTION, {code: -1, msg: e.message});
} else {
throw e;
}
});
}
abort() {
this._requestAbort = true;View on GitHub (pinned to 42343088f2)
Solutions
- Fix the server-side cause so the URL returns 200 (valid token, correct path, available stream)
- Register an onError handler on the loader to receive LoaderErrors.HTTP_STATUS_CODE_INVALID gracefully instead of a thrown exception
- Check the URL and credentials in devtools/network tab and retry with a corrected or refreshed URL
Example fix
// before
const loader = new FetchStreamLoader();
loader.open(...); // throws on 404 because no onError set
// after
const loader = new FetchStreamLoader();
loader.onError = (type, data) => console.error('HTTP', data.code, data.msg);
loader.open(...); Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(url, {method: 'HEAD'});
if (!res.ok) {
throw new Error(`Stream URL unavailable: ${res.status} ${res.statusText}`);
} Type guard
function isOkayResponse(res) {
return typeof res !== 'undefined' && res !== null && typeof res.ok === 'boolean' && res.ok === true;
} Try / catch
loader.onError = (type, data) => {
if (type === LoaderErrors.HTTP_STATUS_CODE_INVALID) {
console.error(`Stream fetch failed: ${data.code} ${data.msg}`);
scheduleRetryWithBackoff();
}
};
try {
loader.open(url);
} catch (e) {
if (e instanceof RuntimeException && e.message.includes('Http code invalid')) {
console.error('Fetch failed without onError handler registered');
} else { throw e; }
} Prevention
- Always register onError on loaders so HTTP failures are reported, not thrown
- Check the URL, auth token, and CORS headers return 200 (verify with curl/HEAD)
- Refresh signed/expired CDN URLs before reopening the stream
- Add retry with backoff for transient 5xx responses
When it happens
Trigger: Fetching an FLV stream URL that returns 404 (file missing), 403 (expired signed URL / wrong token), 5xx (server error), or any non-2xx status, while this._onError is undefined so the else branch throws instead.
Common situations: Expired CDN signatures or auth cookies; CORS misconfiguration surfacing as unexpected status; mis-typed stream URL; forgetting to register loader onError in a custom io pipeline so failures throw instead of being reported.
Related errors
- Fetch stream meet Early-EOF
- MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' +
- MSStreamLoader: Http code invalid, ' + xhr.status + ' ' + xh
- RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.s
- IOException: ' + data.msg
AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01).
Data as JSON: /api/errors/9c0f31bba5a2f7ea.
Report an issue: GitHub.