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

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 get error response message

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

PREVIOUS NEXT
Code Example
Javascript :: express js params 
Javascript :: javascript calculate days between dates 
Javascript :: javascript keep only letters in string 
Javascript :: brightness javascript onload 
Javascript :: enumerate node js 
Javascript :: gradle json simple dependency 
Javascript :: jquery input change while typing 
Javascript :: set defaultValue for select element jsx 
Javascript :: chartjs line disable shadow 
Javascript :: tolocaletimestring short 
Javascript :: angular ngmodel subject 
Javascript :: react post request 
Javascript :: if else jquery click function 
Javascript :: select all checkboxes html js 
Javascript :: count occurrences of character in string javascript 
Javascript :: js convert string to script 
Javascript :: add download buttons in datatable 
Javascript :: node run parameters 
Javascript :: double matrix iteration in react 
Javascript :: js remove extension from filename 
Javascript :: set focus javascript 
Javascript :: jquery get top position of element on scroll 
Javascript :: javascript cookies 
Javascript :: jquery each 
Javascript :: datatable language 
Javascript :: how to clamp a value 
Javascript :: random alphabet javascript 
Javascript :: add and remove checked jquery 
Javascript :: get previous url javascript 
Javascript :: regex to match empty string 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =