getting message from response on error axios code example

Example 1: 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);
    }

Example 2: 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);
});