# Buggy code
def get_repo_data(self, url, response):
    success = False
    try:
        data = response.json()
    except:
        data = json.loads(json.dumps(response.text))

    if "errors" in data:
        logging.info("Error!: {}".format(data["errors"]))
        if data["errors"][0]["message"] == "API rate limit exceeded":
            self.update_gh_rate_limit(response)

    if "id" in data:
        success = True
    else:
        logging.info("Request returned a non-data dict: {}\n".format(data))
        if data["message"] == "Not Found":
            logging.info(
                "Github repo was not found or does not exist for endpoint: {}\n".format(
                    url
                )
            )
        if (
            data["message"]
            == "You have triggered an abuse detection mechanism. Please wait a few minutes before you try again."
        ):
            self.update_gh_rate_limit(r, temporarily_disable=True)
        if data["message"] == "Bad credentials":
            self.update_gh_rate_limit(r, bad_credentials=True)
    if not success:
        self.register_task_failure(
            self.task, repo_id, "Failed to hit endpoint: {}".format(url)
        )

    return data


# Traceback (TypeError)
INFO:root:Worker ran into an error for task: {'job_type': 'MAINTAIN', 'models': ['repo_info'], 'display_name': 'repo_info model for url: https://github.com/davepacheco/node-verror.git', 'given': {'github_url': 'https://github.com/davepacheco/node-verror.git'}}

INFO:root:Printing traceback...

INFO:root:Traceback (most recent call last):
File "/mnt/md0/github/augur-census/workers/worker_base.py", line 189, in collect
model_method(message, repo_id)
File "/mnt/md0/github/augur-census/workers/repo_info_worker/repo_info_worker/worker.py", line 149, in repo_info_model
forked = self.is_forked(owner, repo)
File "/mnt/md0/github/augur-census/workers/repo_info_worker/repo_info_worker/worker.py", line 232, in is_forked
data = self.get_repo_data(self, url, r)
TypeError: get_repo_data() takes 3 positional arguments but 4 were given

INFO:root:This task inserted 0 tuples before failure.

INFO:root:Notifying broker and logging task failure in database...

INFO:werkzeug:127.0.0.1 - - [31/May/2020 18:48:58] "GET /AUGWOP/heartbeat HTTP/1.1" 200 -
INFO:root:Recorded job error in the history table for: {'job_type': 'MAINTAIN', 'models': ['repo_info'], 'display_name': 'repo_info model for url: https://github.com/davepacheco/node-verror.git', 'given': {'github_url': 'https://github.com/davepacheco/node-verror.git'}, 'worker_id': 'com.augurlabs.core.repo_info_worker.50700'}

INFO:root:Updated job process for model: repo_info

# Fixed code
def get_repo_data(self, url, response):
    success = False
    try:
        data = response.json()
    except:
        data = json.loads(json.dumps(response.text))

    if "errors" in data:
        self.logger.info("Error!: {}".format(data["errors"]))
        if data["errors"][0]["message"] == "API rate limit exceeded":
            self.update_gh_rate_limit(response)

    if "id" in data:
        success = True
    else:
        self.logger.info("Request returned a non-data dict: {}\n".format(data))
        if data["message"] == "Not Found":
            self.logger.info(
                "Github repo was not found or does not exist for endpoint: {}\n".format(
                    url
                )
            )
        if (
            data["message"]
            == "You have triggered an abuse detection mechanism. Please wait a few minutes before you try again."
        ):
            self.update_gh_rate_limit(r, temporarily_disable=True)
        if data["message"] == "Bad credentials":
            self.update_gh_rate_limit(r, bad_credentials=True)
    if not success:
        self.register_task_failure(
            self.task, repo_id, "Failed to hit endpoint: {}".format(url)
        )

    return data