error handling for invalid responses