@Snapey in the above:
response.json().then((json) => {
// Do something with JSON body...
});
} else {
// Response was not successful; display error or whatever
}
in // Response was not successful; display error or whatever
The 422 errors are also json, so I would need to repeat
response.json().then((json) => {
To display the validation errors.
Whereas in Axios I can to this:
.then(function (response) {
//console.log(response.data);
var data = response.data;
if (response.status > 199 && response.status < 210) {
showData(data);
}
})
.catch(error => {
if (error.response) {
showData(error.response.data);
}
});
And the function:
function showData(data) {
var div = document.getElementById('msg');
document.getElementById("msg").style.display = "block";
for (var key in data) {
div.innerHTML += " " + data[key];
}
}
In other words:
- Axios js actually treats 422 as error
- Fetch js doesn't treat as error just a response.
I might just use Axios, but my only problem is, will version changes be radical.
I.e., Like the original vue verses the latest version.
Basically I like axois js, but how long will backwards compatibility last?
But I will do another refactor and test things.