Handle database errors properly.