November 2018
Beginner
502 pages
10h 22m
English
.get<IPost[]>("https://jsonplaceholder.typicode.com/postsX")
If we look at the running app, the posts are no longer being rendered.
axios .get<IPost[]>("https://jsonplaceholder.typicode.com/postsX") .then( ... ) .catch(ex => { const error = ex.response.status === 404 ? "Resource not found" : "An unexpected error has occurred"; this.setState({ error }); });
So, unlike fetch, HTTP status error codes can be handled in the catch method. The error object argument in catch contains a response property containing information about the response, including the HTTP status code.
Read now
Unlock full access