I am using axios in reactjs application. My code is like below
axios.post('/api/addresses/upload/',formData,config)
.then(function (response) {
})
.catch(error => {
});
I did not use any console.log()
statement any where but I am getting below error in console
.
How this error printed in console
?
import axios from 'axios'; async function makeRequest() { try { const res = await axios. get('https://example.com/does-not-exist'); const data = res. data; console. log(data); } catch (err) { if (err.
If you know a request is supposed to be quick and you want to give the user quick feedback, you can set a hard timeout in the config passed to axios. get . Axios will throw an error here when the request times out and it'll have an error message like timeout of 30000ms exceeded .
By default, the axios HTTP library throws an error anytime the destination server responds with a 4XX / 5XX error (for example, a 400 Bad Request ). Since axios raises an error, your workflow will stop at this step. See the axios docs for more information.
Axios is a promise based HTTP client for the browser and Node. js. Axios makes it easy to send asynchronous HTTP requests to REST endpoints and perform CRUD operations. It can be used in plain JavaScript or with a library such as Vue or React.
Try by setting the header for the axios request,
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.
May be you will be missing some of your required fields which is mandatory while processing the operations like insertion or updation of a record in your Database. May be you can have the look at it. If everything works well then try the following settings to the header of your request.
If your submitting the form with files then use the header's content-type as
If any cors error occurs then use 'crossDomain': true
var formData = new FormData();
axios.post('/api/addresses/upload/', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With