Skip to content

Commit 477ba70

Browse files
committed
feat: 🎸 add error handling on axios requests
1 parent 12cfe87 commit 477ba70

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

‎src/components/languages.vue‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<z-view style="border-width: 7px;">
3-
3+
<div v-if="sharedState.axiosError !== ''">
4+
Oops!! {{sharedState.axiosError}}
5+
</div>
46
<div v-if="search">
57
<input type="text" placeholder="type a language ..." :value="language"
68
@input="searchLanguages($event.target.value)">
@@ -78,6 +80,10 @@ import axios from 'axios'
7880
function fetchGalleries(results) {
7981
return Promise.all(results.map(record => {
8082
return axios.get('https://github-trending-api.now.sh/repositories?language=' + encodeURIComponent(record.urlParam))
83+
.catch((err) => {
84+
console.log(err);
85+
vm.sharedState.axiosError = err.message
86+
})
8187
})).then(gal => {
8288
var papa = gal.filter(function (el) {
8389
return el.data.length > 0
@@ -150,6 +156,10 @@ export default {
150156
vm.popular = res
151157
vm.other = response.data.all
152158
})
159+
.catch((err) => {
160+
console.log(err);
161+
vm.sharedState.axiosError = err.message
162+
})
153163
}
154164
},
155165
mounted () {

‎src/components/repos.vue‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<z-view :style="showResults ? 'border-width: 7px;' : 'border-width: 7px;'" slider :progress="progress">
33
{{msg}}
4+
<div v-if="sharedState.axiosError !== ''">
5+
Oops!! {{sharedState.axiosError}}
6+
</div>
47
<div v-if="!trending">
58
No trendings for {{sharedState.language}} <br>
69
Create something awesome to be on the spot!
@@ -271,6 +274,7 @@ export default {
271274
axios.get('https://github-trending-api.now.sh/developers?since=' + this.sharedState.since + '&language=' + encodeURIComponent(this.sharedState.language))
272275
])
273276
.then(axios.spread((myjson, github, avatars) => {
277+
vm.sharedState.axiosError = ''
274278
vm.collection = []
275279
var full = github.data.map(function (e, index) {
276280
var search = myjson.data[myjson.data.length - 1][vm.sharedState.since].repos.find(el => el.name === e.name)
@@ -316,6 +320,10 @@ export default {
316320
}
317321
318322
}))
323+
.catch((err) => {
324+
console.log(err);
325+
vm.sharedState.axiosError = err.message
326+
})
319327
}
320328
},
321329
mounted () {

0 commit comments

Comments
 (0)