2017-12-06 1 views
1

Ich habe diese Funktion:Axios 400 Fehler Anforderungsruf dann statt Fang

add(App, Params, Callback){ 
    var self = this; 

    var Data = self.process_fields(Params) 

    self.$http.post(
     paths.api + '/app/' + App.Permalink, 
     new URLSearchParams(Data) 
    ).then(function (error, response) { 
     console.log("then"); 
     if (typeof (Callback) == "function") { 
      Callback(true, response.data.data); 
     } 
    }).catch(function(error){ 
     console.log("catch"); 
     if(typeof error.response !== "undefined"){ 
      errors.render(error.response.data.error) 
     } 

     if (typeof (Callback) == "function") { 
      Callback(false, null); 
     } 
    }); 
} 

Wenn ich Anfrage anrufen und einen 400-Fehler empfangen, es dann statt Fang ruft:

enter image description here

Antwort

2

ich fand die Lösung

Problem durch Dont Rückkehr Versprechen in axios Abfangjäger verursacht:

axios.interceptors.response.use((response) => { 
    return response; 
}, (error) => { 
    if (!error.response) { 
     alert('NETWORK ERROR') 
    } else { 
     const code = error.response.status 
     const response = error.response.data 
     const originalRequest = error.config; 

     if (code === 401 && !originalRequest._retry) { 
      originalRequest._retry = true 

      auth.commit('logout'); 
      window.location.href = "/login"; 
     } 

     return Promise.reject(error) 
    } 
}); 

hinzufügen return Promise.reject(error) funktioniert wie ein Charme