Weird issue - Axios is nulling out a "name" field in a PUT request #6763
Replies: 1 comment
|
The issue is almost certainly that If your data object is a class instance, the Fix: spread to a plain object before sending: put<T = any, R = AxiosResponse<T>>(
url: string,
data?: T,
config?: AxiosRequestConfig
): Promise<R> {
return this.axiosInstance.put<T, R>(url, { ...data } as T, config);
}Or use a JSON round-trip to strip the prototype entirely: return this.axiosInstance.put(url, JSON.parse(JSON.stringify(data)), config);Why this happens:
You can verify by running: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This is very strange. I'm sending a PUT request to update a record using Axios from a React-based front end. I implemented my own abstraction on top of Axios for an HTTP client so I can centralize auth, header config, and whatnot. When I debug the request end-to-end, I can see that the data that gets passed to the the Axois put method contains a
nameproperty with a valid value, but when I inspect what was sent over the wire in devtools, the value isnull.I'm pretty sure the problem isnt here, but this is the put method for my http client built on Axios:
Again, when I put a breakpoint in this method to inspect the value of
data, I can see that it has anameproperty with valid value, but that values is set to null between this operation and the request going out over the wire.Any thoughts as to why Axios would be stripping this value from the request? I am not using any interceptors or anything that could strip this value. I havent tried to go so far as to debug Axois itself, but that may be the next step.
All reactions