fix: detect upstream API errors in stream endpoint to prevent null URL responses

- Added upstream error detection in streamInfo.extractor.js (status >= 400)
- Added non-JSON error string detection from upstream API
- Updated streamInfo.controller.js to return HTTP 502 for upstream failures
- Fixes /api/stream returning null URL when upstream returns error responses
This commit is contained in:
Shinei Nouzen
2026-08-14 06:36:37 +05:30
parent 107e3c71e7
commit 320bf0915b
3 changed files with 39 additions and 2 deletions
+6 -1
View File
@@ -53,7 +53,12 @@ const getStreamInfo = async (req, res, next) => {
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractStreamInfo(id);
let data;
try {
data = await extractStreamInfo(id);
} catch (upstreamError) {
return res.status(502).json({ success: false, message: `Upstream API error: ${upstreamError.message}` });
}
if (!data.url) {
return res.status(404).json({ success: false, message: "Stream URL not found for this link ID", results: data });
}