nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 245 forks source link

NuxtServerError: Request failed with status code 404 when accessing a nonexistent route #373

Closed Seeman13 closed 4 years ago

Seeman13 commented 4 years ago

Hello! I try request on non existent route, but I got this error instead of page 404: Снимок4 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!

Seeman13 commented 4 years ago

I noticed that code not work with use operators async await Снимок6 But this code work! Снимок5

rchl commented 4 years ago

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.

lydiaMag commented 4 years ago

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.

lydiaMag commented 4 years ago

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'
  }
})
Seeman13 commented 4 years ago

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. Снимок7

yc-cool commented 1 year ago

How did you solve it? I encountered the same problem