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

get json data when we get error code in axios

axios.post('/formulas/create', {
	name: "",
	parts: ""
})
.then(response => { 
	console.log(response)
})
.catch(error => {
    console.log(error.response)
});
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

How can I get the status code from an http error in Axios?

axios.get('/foo')
  .catch(function (error) {
    if (error.response) {
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    }
  });
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 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 :: javascript random number between 20 and 30 
Javascript :: flatten array recursively 
Javascript :: generate component in angular 
Javascript :: suspense react 
Javascript :: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements 
Javascript :: split 2 arrays javascript 
Javascript :: if else dart 
Javascript :: js substring first 4 numbwe 
Javascript :: converting strings to numbers 
Javascript :: javascript get day 
Javascript :: conditional array element js 
Javascript :: javascript set time to start of day 12 am 
Javascript :: passing html vlaues to Javascript function 
Javascript :: Update a property of an object of an array 
Javascript :: This version of CLI is only compatible with Angular versions 
Javascript :: get query parameters in node.js 
Javascript :: npm error Could not resolve dependency peer react@"^18.0.0" from react-test-renderer@18.0.0 
Javascript :: copying object javascript 
Javascript :: javascript todataurl 
Javascript :: string uppercase 
Javascript :: how to get folder names with fs 
Javascript :: javascript convert image to base64 
Javascript :: nginx react router 
Javascript :: get date one week from now javascript 
Javascript :: javascript keyup event enter key 
Javascript :: how to use trim in node js 
Javascript :: quasar change port 
Javascript :: CastError: Cast to ObjectId failed for value "undefined" at path "_id" for model 
Javascript :: date get full year 
Javascript :: mongodb push to index 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =