import json


def _get_codes(error_response_json):
    """Get the list of error codes from an error response json"""
    if isinstance(error_response_json, str):
        error_response_json = json.loads(error_response_json)
    error_response_json = error_response_json.get("error")
    if error_response_json is None:
        return []
    code = error_response_json.get('code')
    if code is None:
        raise ValueError("Error response does not contain an error code.")
    codes = [code]
    inner_error = error_response_json.get(
        'inner_error', error_response_json.get('innerError', None))
    while inner_error is not None:
        code = inner_error.get('code')
        if code is None:
            break
        codes.append(code)
        inner_error = inner_error.get(
            'inner_error', inner_error.get('innerError', None))
    return codes[::-1]