ソースを参照

fetching streaminfo is more tolerant

boyska 2 年 前
コミット
b21596d1d7
1 ファイル変更19 行追加16 行削除
  1. 19 16
      radiomanifest.js

+ 19 - 16
radiomanifest.js

@@ -108,24 +108,27 @@ async function get (siteurl, options) {
   resp = null
   try {
     resp = await fetch(getStreaminfoUrl(siteurl))
-    text = await resp.text()
-
-    const data = JSON.parse(text)
-    const name = data['icy-name']
-    if (name !== undefined) {
-      manifest.setName(name)
-    }
   } catch (e) {
-    if (e instanceof TypeError && e.message.startsWith('NetworkError')) {
-      // the fetch has failed
-      true
-    } else if (e instanceof SyntaxError && e.message.startsWith('JSON.parse')) {
-      true
-    } else {
-      console.error('Error', e)
-      throw e
-    }
+    true
   }
+	if(resp !== null) {
+		try {
+			text = await resp.text()
+
+				const data = JSON.parse(text)
+				const name = data['icy-name']
+				if (name !== undefined) {
+					manifest.setName(name)
+				}
+		} catch (e) {
+			if (e instanceof SyntaxError) {
+				true
+			} else {
+				console.error('Error', e)
+					throw e
+			}
+		}
+	}
 
   // XXX: in base alle options fai fetch anche di altra roba
   return manifest