From 51fcac95cdd943c3b316b001b5f60b5f2f6c09a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=BD=C3=A1ra?= Date: Wed, 24 Jun 2020 13:40:29 +0200 Subject: [PATCH] yt error handling --- app/cyp.js | 20 ++++++++++++-------- app/js/elements/yt.js | 20 ++++++++++++-------- index.js | 4 ++-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/cyp.js b/app/cyp.js index 180de37..362b27b 100644 --- a/app/cyp.js +++ b/app/cyp.js @@ -1455,15 +1455,19 @@ class YT extends Component { let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(ytLimit)}`; let response = await fetch(url); - let results = await response.json(); + if (response.status == 200) { + let results = await response.json(); + results.forEach(result => { + let node = new YtResult(result.title); + this.appendChild(node); + node.addButton("download", () => this._download(result.id)); + }); + } else { + let text = await response.text(); + alert(text); + } this._search.pending(false); - - results.forEach(result => { - let node = new YtResult(result.title); - this.appendChild(node); - node.addButton("download", () => this._download(result.id)); - }); } @@ -1497,7 +1501,7 @@ class YT extends Component { const wasHidden = this.hidden; this.hidden = !isThis; - if (!wasHidden && isThis) { this._showRoot(); } + if (!wasHidden && isThis) { this._clear(); } } } diff --git a/app/js/elements/yt.js b/app/js/elements/yt.js index 9d37499..e58e101 100644 --- a/app/js/elements/yt.js +++ b/app/js/elements/yt.js @@ -41,15 +41,19 @@ class YT extends Component { let url = `/youtube?q=${encodeURIComponent(query)}&limit=${encodeURIComponent(conf.ytLimit)}`; let response = await fetch(url); - let results = await response.json(); + if (response.status == 200) { + let results = await response.json(); + results.forEach(result => { + let node = new Result(result.title); + this.appendChild(node); + node.addButton("download", () => this._download(result.id)); + }); + } else { + let text = await response.text(); + alert(text); + } this._search.pending(false); - - results.forEach(result => { - let node = new Result(result.title); - this.appendChild(node); - node.addButton("download", () => this._download(result.id)); - }); } @@ -83,7 +87,7 @@ class YT extends Component { const wasHidden = this.hidden; this.hidden = !isThis; - if (!wasHidden && isThis) { this._showRoot(); } + if (!wasHidden && isThis) { this._clear(); } } } diff --git a/index.js b/index.js index c0641ae..af49d39 100644 --- a/index.js +++ b/index.js @@ -15,9 +15,9 @@ function searchYoutube(q, limit, response) { console.log("YouTube searching", q, limit); q = escape(`ytsearch${limit}:${q}`); - const command = `${cmd} -j ${q} | jq "{id,title}" | jq -s .`; + const command = `set -o pipefail; ${cmd} -j ${q} | jq "{id,title}" | jq -s .`; - require("child_process").exec(command, {}, (error, stdout, stderr) => { + require("child_process").exec(command, {shell:"/bin/bash"}, (error, stdout, stderr) => { if (error) { console.log("error", error); response.writeHead(500);