N
Nuxt2y ago
Rifat

Doesn't show error page if called from inside an async function.

methods:{
async getPosts(time = 0) {
let got = await fetch('/getPosts', { method: 'POST', body: JSON.stringify({ section: '*', modifiedAfter: time }) })
.then(r => r.json())
.catch(fetchError)

if (got.success) {
this.posts.push(...got.docs)
if (got.docs.length < got.limit) this.reachedEnd = true
this.sections = got.sections
// return
}

throw createError({ fatal: true })
}
}
methods:{
async getPosts(time = 0) {
let got = await fetch('/getPosts', { method: 'POST', body: JSON.stringify({ section: '*', modifiedAfter: time }) })
.then(r => r.json())
.catch(fetchError)

if (got.success) {
this.posts.push(...got.docs)
if (got.docs.length < got.limit) this.reachedEnd = true
this.sections = got.sections
// return
}

throw createError({ fatal: true })
}
}
11 Replies
Rifat
RifatOP2y ago
Here I'm manually triggering this error.
danielroe
danielroe2y ago
Where are you calling that function?
Rifat
RifatOP2y ago
mounted() {
this.getPosts()
}
mounted() {
this.getPosts()
}
Rifat
RifatOP2y ago
Throws error in the console though
No description
danielroe
danielroe2y ago
If you want to show an error page at that point you can use showError.
Rifat
RifatOP2y ago
Thanks. showError worked. But why createError doesn't work?
danielroe
danielroe2y ago
It's being called in mounted, so it's not being caught and handled anywhere
Rifat
RifatOP2y ago
showError also logs error in the console. Is there any way to get rid of that?
Rifat
RifatOP2y ago
No description
Rifat
RifatOP2y ago
Will that error cause any problem? or just console.error() that won't cause problems? BTW thanks lot for spending your precious time helping me.
danielroe
danielroe2y ago
No, it won't cause any issues
Want results from more Discord servers?
Add your server