Vonox
Vonox
NNuxt
Created by Vonox on 1/17/2023 in #❓・help
Redirect user when useFetch fails
Works like a charm! Thank you very much 😁
8 replies
NNuxt
Created by Vonox on 1/17/2023 in #❓・help
Redirect user when useFetch fails
I can see my error message in the console, but other than that nothing happens
8 replies
NNuxt
Created by Vonox on 1/17/2023 in #❓・help
Redirect user when useFetch fails
Great example! However error seems to be null in my template. I'm not exactly sure how to throw an error from my API endpoint, any idea? Right now it looks something like this: server/api/products.js
import { firestore } from '../utils/firebase'

export default defineEventHandler(async event => {
const query = getQuery(event)

const snapshot = await firestore.collection('products').doc(query.id).get()

if (snapshot.exists) {
// code
} else {
throw new Error(`Product with id ${query.id} does not exist`)
}
})
import { firestore } from '../utils/firebase'

export default defineEventHandler(async event => {
const query = getQuery(event)

const snapshot = await firestore.collection('products').doc(query.id).get()

if (snapshot.exists) {
// code
} else {
throw new Error(`Product with id ${query.id} does not exist`)
}
})
8 replies