Closed Seeman13 closed 4 years ago
I noticed that code not work with use operators async await But this code work!
You are re-throwing the error in your first example so that will propagate to Nuxt and trigger page error. Don't do throw error
from your catch (error)
handler.
I got the same error when accessing a static existing route , I tried with promise and with async await and both result with the same error . I run json-server on port 3000 and nuxt project on port 3333, The json-server is working properly but axios call return always with 404 error.
When I created EventService with basic url all is working well , I think nuxt axios needs basic url
const apiClient = axios.create({
baseURL: `http://localhost:3000`,
withCredentials: false,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
})
Thanks everyone for answers! I have decided this task long time. It is working variant. I don't remember exactly what was wrong. But the essence of error was in incorrect params variable. Data was with value undefined.
How did you solve it? I encountered the same problem
Hello! I try request on non existent route, but I got this error instead of page 404: My query in store:
async setData ({ commit }, { params, filters }) { try { const { data } = await this.$axios.$get('api/all-data', { params, paramsSerializer: () => qs.stringify(Object.assign(params, filters), { arrayFormat: 'repeat', strictNullHandling: true, skipNulls: true }) }) commit('SET_DATA', data) } catch (error) { throw error } }
Var params have next show: .... { city, category: route.params.category, part } ....If I change params on ...params all ok, no error, but query send without params. If I send query with simple params correct - all ok. But if at least one parameter is set incorrectly, i.e. for example, given a city that does not exist, an error always occurs.
On native Vue with axios the same query work correct!