Close curl session after retrieving error