Status Codes (200, 400, 401, 404, 500)
Every API response includes a status code that tells you if the request succeeded or failed. **Common codes:** ``` 200: OK (success) 201: Created (new resource made) 400: Bad Request (you sent wrong data) 401: Unauthorized (not logged in) 403: Forbidden (logged in but no permission) 404: Not Found (resource doesn't exist) 500: Internal Server Error (something broke on the server) ```
const response = await fetch('/api/users/999')
if (response.status === 404) {
console.log("User not found")
} else if (response.status === 200) {
const user = await response.json()
console.log(user)
}