Behaviour of Axios causing 400
See original GitHub issueSummary
I am having an error with a Yii2 based application where a fetch
call successfully submits but switching out for axios
returns a 400. I have been unsuccessful in fixing this issue. My current code is as follows, where form
is the DOM element.
var args = { method: 'POST', body: new FormData(form), data:{}, config: { headers: {'Content-Type': 'multipart/form-data' } } }
// Submit form and update previousState
fetch("/", args).then(()=>setContent(form));
// axios("/", args).then(()=>setContent(form));
I have tried playing around with the args and such, but didn’t fix it.
The result from the server when fetch
is used is 200 OK
and when axios
is used it returns 400 Bad Request
The follow stack traces
Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:59)
dispatchXhrRequest | @ | xhr.js:172
-- | -- | --
| xhrAdapter | @ | xhr.js:11
| dispatchRequest | @ | dispatchRequest.js:59
| Promise.then (async) | |
| request | @ | Axios.js:53
| wrap | @ | bind.js:9
| _callee2$ | @ | autosave.js:162
| tryCatch | @ | runtime.js:45
| invoke | @ | runtime.js:271
| prototype.<computed> | @ | runtime.js:97
| asyncGeneratorStep | @ | asyncToGenerator.js:3
| _next | @ | asyncToGenerator.js:25
| Promise.then (async) | |
| asyncGeneratorStep | @ | asyncToGenerator.js:13
| _next | @ | asyncToGenerator.js:25
| eval | @ | asyncToGenerator.js:32
| eval | @ | asyncToGenerator.js:21
| submit | @ | autosave.js:91
(autosave.js is my file)
Context
axios@^0.19.0: version “0.19.0” node v10.16.0 Mac OS 10.14.6 running mamp PRO 5.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
How to catch the body of an AXIOS error - DEV Community
In many instances the status of our request may return some kind of error (400, 500), and when this happens we would like...
Read more >Getting 400 error Bad request using axios - Stack Overflow
I am using react-redux and trying to send a post request to localhost:3000/posts. Here is the code that I am using. import axios...
Read more >axios bad request 400 | The AI Search Engine You Control
I keep getting a 400 bad request from Axios. I can pass a GET request and confirm its working fine. I create http-common.js...
Read more >Handling Errors | Axios Docs
axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status code // that falls ......
Read more >[Solved]-Axios 400 error request call then instead of catch-Vue.js
This is on purpose in older version of Axios. validateStatus has been added into config since v0.11. We can use this option to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Axios and fetch have different apis, and the same set of args wont be compatible between them.
Eg, this fetch request;
Would look like this in Axios;
If you’re still having issues check the network tab to see if the request body is being sent correctly. Also, StackOverflow is more suitable for questions like this as it’s not an issue with Axios.
getting error for get request