Handle error events more gracefully