Grokking TypeScript
Vote

0% completed

​

Fetching Data with Fetch and Axios

A request for a user who does not exist comes back with status 404, and fetch treats that as a success:

async function showMissingUser() { const response = await fetch("https://jsonplaceholder.typicode.com/users/1000"); console.log(response.ok, response.status); console.log(await response.json()); } showMissingUser();
false 404 {}

Nothing threw an error, and no .catch would have run. This behavior is a major practical difference between the two common ways to call an API from TypeScript: the fetch function, and a library called axios

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content