[Vuejs]-Axios interceptors don't send data to API in production Heroku app

1👍

I’m not sure what you’re trying to do with transformRequest but that probably isn’t what you want.

A quote from the documentation, https://github.com/axios/axios#request-config:

The last function in the array must return a string or an instance of Buffer, ArrayBuffer, FormData or Stream

If you just return a normal JavaScript object instead it will be mangled in the way you’ve observed.

transformRequest is responsible for taking the data value and converting it into something that can actually be sent over the wire. The default implementation does quite a lot of work manipulating the data and setting relevant headers, in particular Content-Type. See:

https://github.com/axios/axios/blob/885ada6d9b87801a57fe1d19f57304c315703079/lib/defaults.js#L31

If you specify your own transformRequest then you are replacing that default, so none of that stuff will happen automatically.

Without knowing what you’re trying to do it’s difficult to advise further but you should probably use a request interceptor rather than transformRequest for whatever it is you’re trying to do.

Leave a comment