better error handling for curl