Handle errors in connection