Add more robust error handling for unexpected response types