Skip to content

Commit 65e33f0

Browse files
Error handling for omnibox
1 parent 3e94581 commit 65e33f0

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/public/js/omnibox.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
async function omniBox(query) {
2-
const results = await fetch(`/search=${query}`).then((res) => res.json());
2+
let results;
3+
if (query.startsWith("http:") || query.startsWith("https:")) {
4+
results = [[], []];
5+
}
6+
else {
7+
results = await fetch(`/search=${query}`).then((res) => res.json()).catch((err) => console.log("OmniBox Error ignoring..."));
8+
}
39
document.getElementById("omnibox-list").innerHTML = '';
410
document.getElementById("uv-form").style.marginTop = "120px";
511
document.getElementById("omnibox").removeAttribute("class", "dnone");
6-
await results[1].forEach((result) => {
7-
//the only issue is that this passes passed the height of the omnibox and so it needs to be fixed
8-
document.getElementById("omnibox-list").innerHTML += `
9-
<li class="omniBoxResult" onclick="omniBoxSelect('${result}')">${result}</li>
10-
<div id="seperator"></div>
11-
`
12-
});
12+
try {
13+
await results[1].forEach((result) => {
14+
//the only issue is that this passes passed the height of the omnibox and so it needs to be fixed
15+
document.getElementById("omnibox-list").innerHTML += `
16+
<li class="omniBoxResult" onclick="omniBoxSelect('${result}')">${result}</li>
17+
<div id="seperator"></div>
18+
`
19+
});
20+
}
21+
catch (err) {
22+
results = [[], []];
23+
}
1324
if (results[1].length == 0) {
1425
document.getElementById("omnibox-list").innerHTML = ''
1526
document.getElementById("uv-form").style.marginTop = "20px";

0 commit comments

Comments
 (0)