[Vuejs]-Is there any way to catch the response data which is causing the POST 400 (Bad Request) for Vue js fetch api?

0👍

You can inject an error handler that captures the information you want, like with onError below.

function apiService(endpoint, method, data, onError) {
  // D.R.Y. code to make HTTP requests to the REST API backend using fetch
  const config = {
    method: method || "GET",
    body: data !== undefined ? JSON.stringify(data) : null,
    headers: {
      'content-type': 'application/json',
      'X-CSRFTOKEN': CSRF_TOKEN
    }
  };
  return fetch(endpoint, config)
           .then(handleResponse)
           .catch(onError)
}

let len = this.rowObject.length;
for (var i = 0; i <len; i++) {
  let onError = error => console.log("Error on rowObject " + i + ": " + error);
  apiService(endpoint, method, this.rowObject[i], onError);                   
}

Leave a comment