Better error handling for CURL code