<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def edit(self, entity, id, payload, sync=True):
 """ Edit a document. """

        url = urljoin(self.host, entity.value + '/')
        url = urljoin(url, id + '/')
        params = {'sync': str(sync).lower()}
        url = Utils.add_url_parameters(url, params)
        r = requests.put(url, auth=self.auth, data=json.dumps(payload),
                         headers=self.headers)
        if r.status_code == 500:
            error_message = r.json()['error_message']
            raise CoredataError('Error! {error}'.format(error=error_message))