Handle database errors gracefully