Fetching details from the dictionary...
to turn misfortune into fortune (esp. through one's own efforts); to turn the potential disaster to one's advantage