Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture raw axios request from AWS Lambda

I have code that calls a vendor API to do a formdata upload of a file by axios from inside an AWS Lambda. The call returns a 400 error. If I run the code locally using the same node version v14 it works. I want to capture both raw requests and compare them for differences. How do I capture both raw requests? I've tried using ngrok and pipedream but they don't show the raw but decode the request and the file.

  let response = null;
  try {
    const newFile = fs.createReadStream(doc);
    const formData = new FormData();
    formData.append("file", newFile);
    formData.append("url", url);
    const headers = {
      Authorization: "Bearer " + token,
      ...formData.getHeaders(),
    };
    console.log("Headers: ", headers);

    response = await axios.post(`${APIBASE}/file/FileUpload`, formData, {
      headers,
    });
    console.log("file upload response", response);
  } catch (err) {
    console.log("fileupload error at API", err);
  }
like image 262
Greg Pagendam-Turner Avatar asked Jul 12 '26 19:07

Greg Pagendam-Turner


1 Answers

You might be able to just use a custom request interceptor and interrogate at the requests that way.

https://axios-http.com/docs/interceptors

like image 69
Neil.Work Avatar answered Jul 14 '26 23:07

Neil.Work



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!