Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

axios try catch get error status cocxe

     try {
     	await axios.get('/bad-call')
     } catch (error) {
        const err = error as AxiosError
        if (err.response) {
           console.log(err.response.status)
           console.log(err.response.data)
        }
        this.handleAxiosError(error)
     }
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 try catch

try {
    const { data } = await axios({
        method: 'put',
        url: '/api/article/123',
        data: {
            title: 'Making PUT Requests with Axios',
            status: 'published'
        }
    });

    console.log(data);
} catch (err) {
    if (err.response.status === 404) {
        console.log('Resource could not be found!');
    } else {
        console.log(err.message);
    }
}
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 200 goes into then and catch

this issue happen when your response have an error , for example when the response is correct but in the then response you do something that throw an error , axios then catch that error , even if the response from the server was success
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to remove tashkeel from arabic charactor 
Javascript :: no unuseds varsnreactjs 
Javascript :: ionic vue electron 
Javascript :: javascripts 3 months daterange 
Javascript :: How to Create a “Sticky” Floating Footer Bar in WordPress 
Javascript :: Comparison Primitive operations Methods 
Javascript :: javascript bitset 
Javascript :: alert message in js 
Javascript :: how to detect two objects overlapping in javascript 
Javascript :: jaavascript loop array 
Javascript :: react grid generator 
Javascript :: check screen rotated js 
Javascript :: switch is not exported from react-router-dom 
Javascript :: javascript fat arrow functions 
Javascript :: check if key in dictionary javascript 
Javascript :: grapql file upload 
Javascript :: bug in javascript 
Javascript :: node.js version change to 6.14.15 windows 
Javascript :: js hex to string 
Javascript :: Standard conventions for indicating a function argument is unused in JavaScript 
Javascript :: React Liked Component 
Javascript :: safari technology 
Javascript :: jboss-ejb-client.propeties exampe de configuration 
Javascript :: signed url to get file from s3 bucket 
Javascript :: resolveAssetSource react-native-web 
Javascript :: js sol 
Javascript :: assignment of struct in solidity 
Javascript :: javascript centuries 
Javascript :: Edit todo list react-redux 
Javascript :: reactRender 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =