return an error if an invalid response is returned