{"record":{"id":"c35e414fe087aed7","repo":"bilibili/flv.js","slug":"msstreamloader-http-code-invalid-xhr-status","errorCode":null,"errorMessage":"MSStreamLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText","messagePattern":"MSStreamLoader: Http code invalid, ' \\+ xhr\\.status \\+ ' ' \\+ xhr\\.statusText","errorType":"http","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/io/xhr-msstream-loader.js","lineNumber":217,"sourceCode":"                    }\n                }\n\n                let lengthHeader = xhr.getResponseHeader('Content-Length');\n                if (lengthHeader != null && this._contentLength == null) {\n                    let length = parseInt(lengthHeader);\n                    if (length > 0) {\n                        this._contentLength = length;\n                        if (this._onContentLengthKnown) {\n                            this._onContentLengthKnown(this._contentLength);\n                        }\n                    }\n                }\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('MSStreamLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);\n                }\n            }\n        } else if (xhr.readyState === 3) {  // LOADING\n            if (xhr.status >= 200 && xhr.status <= 299) {\n                this._status = LoaderStatus.kBuffering;\n\n                let msstream = xhr.response;\n                this._reader.readAsArrayBuffer(msstream);\n            }\n        }\n    }\n\n    _xhrOnError(e) {\n        this._status = LoaderStatus.kError;\n        let type = LoaderErrors.EXCEPTION;\n        let info = {code: -1, msg: e.constructor.name + ' ' + e.type};\n\n        if (this._onError) {","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/io/xhr-msstream-loader.js#L199-L235","documentation":"MSStreamLoader (IE/Edge MSStream XHR path) validates the HTTP status at readyState 2. A status outside 200-299 (and not 0) sets the loader to kError and, when no onError callback is registered, throws RuntimeException with the status code and statusText. It means the server refused or failed the segmented stream request.","triggerScenarios":"The XHR loading the FLV stream receives 404/403/5xx headers in _xhrOnReadyStateChange (src/io/xhr-msstream-loader.js:217), typically at request open on IE/Edge where MSStream is used.","commonSituations":"Expired or invalid query-string auth on the media URL, stream removed from the server, or redirect to an HTML error page — surfacing only on legacy IE/Edge playback.","solutions":["Verify the URL returns 200 (curl -I) and fix server-side availability or authentication.","Attach an onError handler so LoaderErrors.HTTP_STATUS_CODE_INVALID is delivered to your code instead of thrown.","Implement URL refresh/retry with a backup source for long-lived streams."],"exampleFix":"// before\nloader.load(url); // long-lived signed URL\n// after\nsetInterval(() => loader.updateUrl(reSign(url)), 4 * 60 * 1000); // refresh before expiry","handlingStrategy":"retry","validationCode":"async function ensurePlayable(url) {\n    const res = await fetch(url, {method: 'HEAD'});\n    if (res.status < 200 || res.status > 299) throw new Error('Bad status ' + res.status);\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    player.load();\n} catch (e) {\n    if (/MSStreamLoader: Http code invalid/.test(e.message)) {\n        setTimeout(() => { player.unload(); player.load(); }, backoffMs);\n    } else throw e;\n}","preventionTips":["Refresh time-limited query-string auth tokens before they expire on long streams.","Verify the URL works on IE/Edge specifically (legacy loader path).","Register onError and retry with a re-signed URL on 403, alternate URL on 404."],"tags":["http","network","loader","internet-explorer"],"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"}