Skip to content

Commit

Permalink
update error handling logic for axios
Browse files Browse the repository at this point in the history
  • Loading branch information
Amorpheuz committed May 16, 2021
1 parent 32c4b25 commit d04d756
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,18 @@
/>
</div>
</div>
<div v-else-if="!searchResults.length && !isLoading" class="mt-6">
<lazy-cat-404 v-if="error && Math.floor(error.errorCode) === 404" />
<div
v-else-if="
!searchResults.length &&
error &&
Object.keys(error).length &&
!isLoading
"
class="mt-6"
>
<lazy-cat-404 v-if="Math.floor(error.errorCode) === 404" />
<p v-else>
Error {{ Math.floor(error.errorCode) }} : {{ error.error }}
Error {{ Math.floor(error.errorCode) }} : {{ error.error.error }}
</p>
</div>
</div>
Expand Down Expand Up @@ -127,6 +135,7 @@ export default {
},
methods: {
searchBreed() {
this.error = {}
if (this.searchStr) {
this.isLoading = true
this.firstLoad = false
Expand Down Expand Up @@ -165,12 +174,12 @@ export default {
}
}
})
if (searchRes.success) {
if (searchRes && searchRes.success) {
this.resultCount = searchRes.dataCount
this.searchResults = searchRes.data
this.nextDisable =
this.resultCount < (this.pageNum + 1) * this.countPerPage
} else if (searchRes.errorCode) {
} else if (searchRes && searchRes.errorCode) {
this.resultCount = 0
this.searchResults = []
this.error = searchRes
Expand Down

0 comments on commit d04d756

Please sign in to comment.