N
Nuxt3y 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
RifatOP3y ago
Here I'm manually triggering this error.
danielroe
danielroe3y ago
Where are you calling that function?
Rifat
RifatOP3y ago
mounted() {
this.getPosts()
}
mounted() {
this.getPosts()
}
Rifat
RifatOP3y ago
Throws error in the console though
No description
danielroe
danielroe3y ago
If you want to show an error page at that point you can use showError.
Rifat
RifatOP3y ago
Thanks. showError worked. But why createError doesn't work?
danielroe
danielroe3y ago
It's being called in mounted, so it's not being caught and handled anywhere
Rifat
RifatOP3y ago
showError also logs error in the console. Is there any way to get rid of that?
Rifat
RifatOP3y ago
No description
Rifat
RifatOP3y 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
danielroe3y ago
No, it won't cause any issues

Did you find this page helpful?