1

I'm sending a base64 string to a backend with axios, but it can only be sent if the string is not over 2MB long. if it's longer than that I want to console.log the error message, but it doesn't work - because I can't reach the catch block of the try-catch. I see an error message in the console that says I can't send it because the payload is too large, but I don't see the error message I tried to console.log. It's really important because in addition I want to change some state inside the catch block, but I just can seem to reach it.

const base64image = JSON.stringify({long base64 string of encoded image})
  try {
      axios
        .post(
          'someurl',
          base64image,
          {
            headers: {
              'Content-Type': 'application/json',
            },
          }
        )
        .then((res) => {
          console.log(
            'success ' + JSON.stringify(res.data)
          );
        })
        .catch((err) => {
          if (err.res) {
            console.log('failure: ' + err.res.data.message);
          }
        });
    } catch (e) {
      console.log(e);
    }
  };
rozina
  • 53
  • 1
  • 3

0 Answers0