Answers for "axios post error handling"

5

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);
});
Posted by: Guest on May-05-2021
11

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)
     }
Posted by: Guest on May-24-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language