Skip to content
Snippets Groups Projects
Commit e5b0a527 authored by schneider210's avatar schneider210
Browse files

refactor: wrap request logic into try-catch-block

parent 7f43a999
No related branches found
No related tags found
1 merge request!60loading indicator for search
Pipeline #219796 passed with warnings
...@@ -81,23 +81,20 @@ export default { ...@@ -81,23 +81,20 @@ export default {
this.search(this.query, 0, this.size) this.search(this.query, 0, this.size)
}, },
async search(value, from, size) { async search(value, from, size) {
let searchResponse; this.loading = false;
try { try {
searchResponse = await apiService.search(value, from, size); const searchResponse = await apiService.search(value, from, size);
} catch(error) { const items = searchResponse.hits?.hits;
// handle error here ...
} finally {
this.loading = true;
}
if (searchResponse) {
this.loading = false;
const items = searchResponse.hits?.hits;
if (items) { if (items) {
this.total = searchResponse.hits?.total.value || 0; this.total = searchResponse.hits?.total?.value || 0;
this.items = items.map(x => ({ ...x, searchTerm: value })); this.items = items.map(x => ({ ...x, searchTerm: value }));
} }
} catch(error) {
console.log(error.message);
} finally {
this.loading = true;
} }
}, },
scrollUp() { scrollUp() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment