retry middleware correctly processes exception