Skip to content

Commit 8f5ed49

Browse files
committed
Only append results if response.ok
1 parent 2cb6b91 commit 8f5ed49

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,23 @@ async function fetchResults(remoteInput: RemoteInputElement, checkCurrentQuery:
7070

7171
remoteInput.dispatchEvent(new CustomEvent('loadstart'))
7272
remoteInput.setAttribute('loading', '')
73+
let response, html
7374
try {
74-
const response = await fetch(url, {
75+
response = await fetch(url, {
7576
credentials: 'same-origin',
7677
headers: {accept: 'text/html; fragment'}
7778
})
78-
const html = await response.text()
79+
html = await response.text()
7980
remoteInput.dispatchEvent(new CustomEvent('load'))
80-
resultsContainer.innerHTML = html
8181
} catch {
82+
// noop
83+
}
84+
if (response && response.ok && html) {
85+
resultsContainer.innerHTML = html
86+
} else {
8287
remoteInput.dispatchEvent(new CustomEvent('error'))
8388
}
89+
8490
remoteInput.removeAttribute('loading')
8591
remoteInput.dispatchEvent(new CustomEvent('loadend'))
8692
}

0 commit comments

Comments
 (0)