Small code refactor on handle_socket_error