Axios catch a valid response 201 and treat it as an error
See original GitHub issue#### Summary
Hello , i am having this weird issue related to axios with laravel , when i submit a form using ajax the status code that i receive from laravel api is 201 or 200 but the axios only catch them as error
axios.post(this.url, formData)
.then(
(response) => {
console.log(response.status); // return 201
const { data } = response
vm.$notify({
type: 'success',
duration: 10000,
speed: 1000,
title: $t('labels.' + data.message),
text: $t('messages.' + data.message)
});
}
)
.catch(e => {
vm.$notify({
type: 'error',
duration: 10000,
speed: 1000,
text: e.response
});
//vm.$emit('form-errors', e.response.data.errors);
})
the return value from the api is
{success: true, message: "created"}
with status code of 201
#### Context
- axios version: e.g.: v0.17.1
- Environment: *e.g.: node v8.4.0, macOs, vue 2.5.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:13
Top Results From Across the Web
How can I get the status code from an HTTP error in Axios?
axios.get('/foo') .catch(function (error) { if (error.response) ... returned from the server, you can add validateStatus: status => true to axios options:
Read more >Axios catch a valid response 201 and treat it as an error
Summary. Hello , i am having this weird issue related to axios with laravel , when i submit a form using ajax the...
Read more >Handling Errors | Axios Docs
Handling Errors. axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status ...
Read more >axios show status false
Insert data in database successfully but axios response.status === 201 show false Network tab also show 201 status. any one know what i...
Read more >HTTP status and error codes for JSON | Cloud Storage
Error Response Format. Cloud Storage uses the standard HTTP error reporting format for the JSON API. Successful requests return HTTP status codes in...
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 Free
Top 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
I had the same problem, and i see a dependence unsolved on my .then(). When exploded the exception the flow followed to .catch().
in other words, the request code 201,200…(20*) go to catch() only if there is a error in .then().
this issue happen when your response have an error , for example when the response is correct but in the then response you do something that throw an error , axios then catch that error , even if the response from the server was success, i hope i am making sense