Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to handle error axios js

axios.post("/api/end", {data : "xx"})
  .then(({ data }) => {
  // doing something with success
  })
  .catch((err) => {
  let message = typeof err.response !== "undefined" ? err.response.data.message : err.message;
  console.warn("error", message);
});
Comment

axios get error message

  .catch(function (error) {
    if (error.response) {
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    }
Comment

axios call error handling

axios.get('/api/xyz/abcd')
  .catch(function (error) {
    if (error.response) {
      // Request made and server responded
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      console.log(error.request);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.log('Error', error.message);
    }

  });
Comment

axios error

axios.get('/api/xyz/abcd')
  .catch(function (error) {
    if (error.response) {
      // Request made and server responded
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      console.log(error.request);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.log('Error', error.message);
    }

  });
Comment

axios how to get error response

axios.post('/formulas/create', {
	name: "",
	parts: ""
})
.then(response => { 
	console.log(response)
})
.catch(error => {
    console.log(error.response)
});
Comment

axios error message

        .catch((error) => {
		  const errorMessage = error?.response?.data?.message;
          const message = errorMessage || "your custome message";
          this.$toast.show(message, {
            icon: "info",
            className: "toast-danger",
          });
		})
Comment

npm i axios error

npm install --save axios
Comment

axios error handling

const onSubmit = async (FormData) => {
  FormData.bFlats = meters;
  try {
    let res = await axios({
      method: 'post',
      url: 'http://localhost:5000/api/v1/buildings',
      data: FormData
    });

    console.log(res.data);
    if (res.data.status === 'success') {
      alert("Successfully Inserted");
      reset();
    }
  } catch (error) {
    console.log(error.response.data.message); // this is the main part. Use the response property from the error object
  }
}
Comment

axios error network error

// WHEN WORKING WITH LOCALHOST
/* The thing is, that iOS is running in a simulator and Android is running in an emulator.
The localhost is pointing to the environment in which the code is running. 
The emulator emulates a real device while the simulator is only imitating the device.
Therefore the localhost on Android is pointing to the emulated Android device. 
And not to the machine on which your server is running.
The solution is to replace localhost with the IP address of your machine. */
Comment

axios get error response message

axios.get(...).catch( error => { return Promise.reject(error.response.data.error); });
Comment

axios error network error

// WORKING WITH WEB API
// add http or https to your url
// ex: www.themealdb.... -> https://www.themealdb....
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery focus input end of text 
Javascript :: useparams example 
Javascript :: toggle class jquery not working 
Javascript :: javascript get 1 hour from now 
Javascript :: javascript format date time 
Javascript :: express receive post 
Javascript :: react inject component into another component 
Javascript :: upload form with doc type in ajax 
Javascript :: js check if div have another div 
Javascript :: write json file c# 
Javascript :: promise.all async await 
Javascript :: js string to json 
Javascript :: scrollto is not a function javascript 
Javascript :: js host without port 
Javascript :: angular generate without spec 
Javascript :: javascript for each loop 
Javascript :: active js 
Javascript :: responsive calc height react native 
Javascript :: js create object from array 
Javascript :: js get first element of array 
Javascript :: random id generator javascript 
Javascript :: multiply function javascript 
Javascript :: recursion javascript 
Javascript :: react footer 
Javascript :: how to delete node_modules 
Javascript :: patch request javascript 
Javascript :: os module in node js 
Javascript :: how to check if value is undefines if condition jquery 
Javascript :: javascript set variable if not defined 
Javascript :: check user by id discord js 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =