tls: fix some error handling.