Improved error handling by ensuring the expected HTTP status codes.